:root {
  --bg: #0a0b0d;
  --surface: #15171c;
  --surface-2: #1c1f26;
  --surface-3: #23262e;
  --border: #262a33;
  --border-soft: #1d2027;
  --text: #eef0f3;
  --text-dim: #8b92a0;
  --text-faint: #5c6270;
  --accent: #f5b942;
  --accent-soft: rgba(245, 185, 66, 0.1);
  --accent-dim: #b98a2c;
  --win: #4fd190;
  --win-soft: rgba(79, 209, 144, 0.12);
  --loss: #f16d7f;
  --loss-soft: rgba(241, 109, 127, 0.12);
  --neutral: #6b7280;
  --neutral-soft: rgba(107, 114, 128, 0.15);
  --chart-line: #4b5160;
  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 32px -16px rgba(0, 0, 0, 0.6);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  background: rgba(21, 23, 28, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text);
  white-space: nowrap;
  letter-spacing: -0.01em;
  transition: transform 0.15s ease;
}
.brand:hover { text-decoration: none; transform: translateY(-1px); }

.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.1rem;
  animation: brand-pulse 3.2s ease-in-out infinite;
}
@keyframes brand-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 185, 66, 0.35); }
  50% { box-shadow: 0 0 0 6px rgba(245, 185, 66, 0); }
}

.brand-accent {
  background: linear-gradient(90deg, var(--accent), #ffd98a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.search-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 260px;
}

.mode-toggle {
  position: relative;
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  flex-shrink: 0;
}

.mode-indicator {
  position: absolute;
  top: 2px;
  left: 2px;
  bottom: 2px;
  width: calc(50% - 2px);
  border-radius: 999px;
  background: var(--accent);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 0;
}
.mode-toggle.mode-match .mode-indicator { transform: translateX(100%); }

.mode-btn {
  position: relative;
  z-index: 1;
  min-width: 92px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 6px 13px;
  border-radius: 999px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  text-align: center;
  transition: color 0.15s ease;
}

.mode-btn.active {
  color: #1a1305;
  font-weight: 700;
}

#search-input {
  flex: 1;
  min-width: 120px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font: inherit;
  padding: 9px 13px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
#search-input::placeholder { color: var(--text-faint); }
#search-input:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 0 18px rgba(245, 185, 66, 0.12);
}

.search-btn {
  background: var(--accent);
  color: #1a1305;
  border: none;
  font: inherit;
  font-weight: 700;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.search-btn:hover {
  filter: brightness(1.08);
  box-shadow: 0 0 16px rgba(245, 185, 66, 0.35);
  transform: translateY(-1px);
}
.search-btn:active { transform: translateY(0); }

main {
  max-width: 1160px;
  margin: 0 auto;
  padding: 28px 20px 72px;
  min-height: 60vh;
}

.footer {
  text-align: center;
  color: var(--text-faint);
  font-size: 0.78rem;
  padding: 24px 16px 40px;
}

.loading, .error-box, .empty-box {
  text-align: center;
  color: var(--text-dim);
  padding: 80px 20px;
  font-size: 0.95rem;
}
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.error-box { color: var(--loss); }
.empty-box small { color: var(--text-faint); }
.empty-fallback { display: block; margin-top: 16px; font-size: 0.9rem; }

/* Home view */
.hero-panel {
  text-align: center;
  padding: 64px 16px 24px;
}
.hero-panel h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}
.hero-panel p {
  color: var(--text-dim);
  max-width: 540px;
  margin: 0 auto;
  line-height: 1.6;
  font-size: 0.98rem;
}

.tip-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 620px;
  margin: 28px auto 0;
  background: var(--accent-soft);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 0.88rem;
  color: var(--text-dim);
  line-height: 1.6;
}
.tip-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }
.tip-card strong { color: var(--text); }
.tip-card code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.82rem;
  color: var(--accent);
}

.recent-section {
  margin-top: 40px;
}
.recent-section h2 {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 12px;
  text-align: center;
}
.recent-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.recent-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px 6px 6px;
  font-size: 0.85rem;
  color: var(--text);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.recent-chip:hover { border-color: var(--accent-dim); text-decoration: none; }
.recent-chip img { width: 24px; height: 24px; border-radius: 50%; }

/* Search results */
.result-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.result-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.result-card:hover { border-color: var(--accent-dim); background: var(--surface-2); }
.result-card img { width: 46px; height: 46px; border-radius: var(--radius-sm); }
.result-name { font-weight: 600; }
.result-meta { color: var(--text-dim); font-size: 0.82rem; margin-top: 2px; }

/* Player view */
.profile-header {
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}
.profile-header img.avatar {
  width: 76px;
  height: 76px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.profile-name { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.01em; }
.profile-sub { color: var(--text-dim); font-size: 0.85rem; margin-top: 4px; }
.rank-badge { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.rank-badge img { width: 52px; height: 52px; }
.rank-badge .rank-label { text-align: right; font-size: 0.78rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.rank-badge .rank-name { color: var(--text); font-weight: 700; font-size: 0.95rem; text-transform: none; letter-spacing: 0; margin-top: 2px; }

/* Stat strip */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.stat-item {
  padding: 16px 14px;
  text-align: center;
  border-right: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
}
.stat-item .value { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.01em; }
.stat-item .label { color: var(--text-faint); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; margin-top: 5px; font-weight: 600; }
.stat-item.win .value { color: var(--win); }
.stat-item.loss .value { color: var(--loss); }
.stat-item.highlight { background: var(--accent-soft); }
.stat-item.highlight .value { color: var(--accent); font-size: 1.55rem; }

.section-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 12px;
  color: var(--text-faint);
}

/* Trend charts */
.trend-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 14px;
}
.trend-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 16px 12px;
  box-shadow: var(--shadow);
}
.trend-card .section-title { margin-bottom: 6px; }

.line-chart {
  width: 100%;
  height: 108px;
  display: block;
  overflow: visible;
}
.line-chart-fill { fill: var(--accent); opacity: 0.12; }
.line-chart-line {
  fill: none;
  stroke: var(--chart-line);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.chart-point {
  stroke: var(--surface);
  stroke-width: 2;
  cursor: pointer;
  transition: r 0.1s ease;
}
.chart-point:hover { r: 5.5; }
.chart-axis-label {
  fill: var(--text-faint);
  font-family: var(--font);
  font-size: 10px;
  font-weight: 600;
}

.trend-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  font-size: 0.76rem;
  color: var(--text-faint);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.legend-dot.win { background: var(--win); }
.legend-dot.loss { background: var(--loss); }
.trend-refnote { margin-left: auto; }

.player-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 24px;
  align-items: start;
}

/* Hero sidebar */
.hero-sidebar { position: sticky; top: 84px; }

.hero-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px;
  box-shadow: var(--shadow);
}

.hero-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  transition: background-color 0.15s ease;
}
.hero-row:hover { background: var(--surface-2); }
.hero-row.top {
  border-left-color: var(--accent);
  background: var(--accent-soft);
}
.hero-row-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-2);
}
.hero-row-main { flex: 1; min-width: 0; }
.hero-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 0.85rem;
}
.hero-row-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hero-row-count { color: var(--text-faint); font-size: 0.76rem; flex-shrink: 0; }
.hero-row-meta { color: var(--text-dim); font-size: 0.72rem; margin-top: 4px; }

.wr-bar {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  width: 100%;
  height: 4px;
  border: none;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-3);
  margin-top: 6px;
  display: block;
}
.wr-bar::-webkit-progress-bar { background: var(--surface-3); border-radius: 999px; }
.wr-bar::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
.wr-bar::-moz-progress-bar { background: var(--accent); border-radius: 999px; }

/* Match list (grid-table) */
.match-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.match-list-head,
.match-row {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) 80px 94px 72px 92px 68px 84px;
  align-items: center;
  gap: 12px;
  padding: 11px 18px;
  border-left: 3px solid transparent;
}

.match-list-head {
  color: var(--text-faint);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.match-row {
  font-size: 0.87rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border-soft);
  transition: background-color 0.15s ease;
}
.match-row:last-child { border-bottom: none; }
.match-row:hover { background: var(--surface-2); }
.match-row.win { border-left-color: var(--win); }
.match-row.loss { border-left-color: var(--loss); }

.mc-hero { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mc-hero img { width: 32px; height: 32px; border-radius: var(--radius-sm); object-fit: cover; flex-shrink: 0; }
.mc-hero-text { min-width: 0; display: flex; flex-direction: column; }
.mc-hero-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.mc-hero-level { color: var(--text-faint); font-size: 0.72rem; margin-top: 1px; }

.mc-result { justify-self: center; }
.mc-cs, .mc-networth, .mc-duration, .mc-time {
  justify-self: end;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.mc-cs, .mc-networth, .mc-duration { color: var(--text-dim); }
.mc-time { color: var(--text-faint); font-size: 0.82rem; }

.result-tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
}
.result-tag.win { background: var(--win-soft); color: var(--win); }
.result-tag.loss { background: var(--loss-soft); color: var(--loss); }

/* KDA column: the ratio is the headline (color-coded by quality), the raw
   kills/deaths/assists breakdown rides underneath as supporting detail. */
.mc-kda {
  justify-self: end;
  text-align: right;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}
.kda-ratio-big {
  font-weight: 700;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.kda-ratio-big.good { color: var(--win); }
.kda-ratio-big.bad { color: var(--loss); }
.kda-breakdown {
  color: var(--text-faint);
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
}

.kda-ratio { color: var(--text-faint); font-size: 0.8rem; margin-left: 3px; }

/* Match view */
.match-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.match-summary .ms-item {
  text-align: center;
  padding: 16px 14px;
  border-right: 1px solid var(--border-soft);
}
.match-summary .ms-item:last-child { border-right: none; }
.match-summary .ms-item .value { font-weight: 800; font-size: 1.1rem; letter-spacing: -0.01em; }
.match-summary .ms-item .label { color: var(--text-faint); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; margin-top: 5px; font-weight: 600; }

.team-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.team-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 12px 18px;
}
.team-header.winner { background: var(--win-soft); color: var(--win); }
.team-header.loser { background: var(--loss-soft); color: var(--loss); }
.team-header .team-tag {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.2);
}

.team-table-head,
.player-row {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.5fr) 120px 104px 64px;
  align-items: center;
  gap: 12px;
  padding: 9px 18px;
}
.team-table-head {
  color: var(--text-faint);
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.player-row {
  border-bottom: 1px solid var(--border-soft);
  font-size: 0.85rem;
  transition: background-color 0.15s ease;
}
.player-row:last-child { border-bottom: none; }
.player-row:hover { background: var(--surface-2); }

.player-row .prow-hero { display: flex; align-items: center; gap: 8px; min-width: 0; }
.player-row img.hero-icon { width: 28px; height: 28px; border-radius: var(--radius-sm); object-fit: cover; flex-shrink: 0; }
.player-row .prow-hero span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); }

.player-row .pname { display: flex; align-items: center; gap: 8px; min-width: 0; }
.player-row .pname img.pavatar { width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0; }
.player-row .pname span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.player-row a.pname-link { color: var(--text); }
.player-row a.pname-link:hover { color: var(--accent); text-decoration: none; }

.player-row .stat {
  text-align: right;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  z-index: 100;
  box-shadow: var(--shadow);
}
.toast.hidden { display: none; }

@media (max-width: 860px) {
  .player-layout { grid-template-columns: 1fr; }
  .hero-sidebar { position: static; }
  .trend-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .topbar { gap: 10px; padding: 12px 16px; }
  .brand { font-size: 0.95rem; }
  .trend-grid { grid-template-columns: 1fr; }
  .hero-panel h1 { font-size: 1.5rem; }
  .profile-header { flex-direction: column; align-items: flex-start; padding: 16px; }
  .rank-badge { margin-left: 0; }

  .match-list-head, .match-row {
    grid-template-columns: minmax(0, 1fr) 72px 92px;
  }
  .mc-cs, .mc-networth, .mc-duration, .mc-time { display: none; }

  .team-table-head, .player-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 92px;
  }
  .team-table-head span:nth-child(4),
  .team-table-head span:nth-child(5),
  .player-row .stat.wide { display: none; }
}
