/* ── Reset & variables ───────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0d1117;
  --bg2:         #161b22;
  --bg3:         #1c2230;
  --border:      #30363d;
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --accent:      #58a6ff;
  --accent2:     #f0883e;
  --win:         #3fb950;
  --loss:        #f85149;
  --gold:        #d29922;
  --purple:      #a371f7;
  --radius:      8px;
  --shadow:      0 4px 16px rgba(0,0,0,.5);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ──────────────────────────────────────────────── */
.header {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}
.header-inner {
  display: flex; align-items: center; gap: 20px;
  max-width: 1200px; margin: 0 auto; height: 56px;
}
.logo {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none; padding: 0; margin: 0;
  font: inherit; color: inherit; cursor: pointer;
  transition: opacity .15s;
}
.logo:hover { opacity: .8; }
.logo:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.logo-icon { font-size: 20px; }
.logo-text { font-size: 16px; font-weight: 700; letter-spacing: .5px; }
.logo-badge {
  font-size: 10px; font-weight: 700; letter-spacing: 1px;
  background: var(--accent2); color: #000;
  padding: 1px 5px; border-radius: 3px;
}
.header-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.db-status { font-size: 12px; color: var(--text-muted); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; border: none; border-radius: var(--radius);
  cursor: pointer; font-size: 14px; font-weight: 500;
  transition: opacity .15s, background .15s;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #000; padding: 10px 28px; }
.btn-primary:not(:disabled):hover { opacity: .85; }

/* ── Main layout ─────────────────────────────────────────── */
.main {
  max-width: 1100px; margin: 0 auto;
  padding: 24px 16px 64px;
  display: flex; flex-direction: column; gap: 28px;
}
.view { display: flex; flex-direction: column; gap: 20px; }
.view.hidden { display: none; }
.hidden { display: none !important; }

/* ── Search ──────────────────────────────────────────────── */
.search-wrapper { max-width: 640px; margin: 16px auto 0; }
.search-input {
  flex: 1; padding: 12px 16px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 15px;
  outline: none;
}
.search-input:focus { border-color: var(--accent); }

/* ── Autocomplete dropdown ───────────────────────────────── */
.search-input-wrap { position: relative; flex: 1; }
.search-input-wrap .search-input { width: 100%; box-sizing: border-box; }
.ac-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 50;
  margin: 0; padding: 4px; list-style: none;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  max-height: 280px; overflow-y: auto;
}
.ac-item {
  display: flex; align-items: baseline; gap: 8px;
  padding: 8px 12px; border-radius: 6px; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--text);
}
.ac-item:hover, .ac-item.active { background: var(--bg3); }
.ac-item.active { outline: 1px solid var(--accent); }
.ac-item .name { flex: 1; }
.ac-item .team { color: var(--text-muted); font-weight: 500; font-size: 13px; }
.ac-kind {
  flex: none; padding: 2px 7px; border-radius: 4px;
  font-size: 10px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
}
.ac-kind-player   { background: #1a3a5c; color: #58a6ff; }
.ac-kind-team     { background: #2a2030; color: #d2a8ff; }
.ac-kind-role     { background: #1a2a3a; color: #79c0ff; }
.ac-kind-champion { background: #2a2415; color: var(--gold); }

.search-error {
  margin-top: 10px; color: var(--loss); font-size: 13px; font-weight: 600;
}
.quick-chips { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.quick-chip {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 16px; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--text);
  transition: background .15s, border-color .15s;
}
.quick-chip:hover { background: var(--bg3); border-color: var(--accent); }
.quick-chip span { color: var(--text-muted); font-weight: 500; margin-left: 6px; }

/* ── Tags ────────────────────────────────────────────────── */
.tag {
  display: inline-block; padding: 2px 9px;
  border-radius: 4px; font-size: 11px; font-weight: 700; letter-spacing: .5px;
}
.tag-LCK { background: #1a3a5c; color: #58a6ff; }
.tag-role { background: #1a2a3a; color: #79c0ff; }
.tag-team { background: var(--bg3); color: var(--text-muted); }

/* ── Win/loss streak badge ───────────────────────────────── */
.streak-badge {
  display: inline-block; padding: 2px 9px;
  border-radius: 4px; font-size: 11px; font-weight: 700; letter-spacing: .5px;
}
.streak-badge.win { background: var(--win); color: #000; }
.streak-badge.loss { background: var(--loss); color: #000; }

/* Clickable role/team tags (button reset → looks like a tag). */
.tag-link {
  border: 1px solid transparent; cursor: pointer; font-family: inherit;
  transition: border-color .15s, filter .15s;
}
.tag-link:hover { border-color: var(--accent); filter: brightness(1.15); }

/* ── Team / role group view ──────────────────────────────── */
.group-header {
  display: flex; align-items: center; gap: 16px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 24px; margin-top: 12px;
}
.group-sub { color: var(--text-muted); font-size: 13px; font-weight: 600; }

/* Team Elo badge (VIN-21) */
.group-elo {
  margin-left: auto; display: flex; flex-direction: column; align-items: flex-end;
  gap: 6px; text-align: right;
}
.elo-main { display: flex; align-items: baseline; gap: 6px; }
.elo-rating { font-size: 30px; font-weight: 800; color: var(--accent); line-height: 1; }
.elo-rating-label {
  font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  color: var(--text-muted);
}
.elo-meta {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 12px;
  font-size: 12px; color: var(--text-muted);
}
.elo-form { display: flex; align-items: center; gap: 5px; }
.elo-form-label {
  font-size: 11px; font-weight: 600; color: var(--text-muted); margin-right: 2px;
}
.form-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  font-size: 10px; font-weight: 700; color: #000;
}
.form-dot.win { background: var(--win); }
.form-dot.loss { background: var(--loss); }

.group-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.group-card {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  width: 100%; text-align: left; font-family: inherit; cursor: pointer;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px;
  transition: background .15s, border-color .15s;
}
.group-card:hover { background: var(--bg3); border-color: var(--accent); }
.group-card-main { display: flex; flex-direction: column; gap: 3px; }
.group-card-name { font-size: 17px; font-weight: 800; color: var(--text); }
.group-card-meta { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.group-card-perf { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.group-card-wr { font-size: 13px; font-weight: 700; color: var(--text); }
.group-card-wr em { color: var(--text-muted); font-weight: 500; font-style: normal; }

/* ── Performance rating tag ──────────────────────────────── */
.rating-tag {
  display: inline-block; padding: 2px 9px; border-radius: 4px;
  font-size: 11px; font-weight: 700; letter-spacing: .5px;
}
.rating-strong     { background: rgba(63, 185, 80, .18);  color: var(--win); }
.rating-average    { background: var(--bg3);              color: var(--text-muted); }
.rating-struggling { background: rgba(248, 81, 73, .18);  color: var(--loss); }

/* ── Detail hero + filters ───────────────────────────────── */
.detail-hero {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 24px;
}
.detail-name { font-size: 28px; font-weight: 900; margin-bottom: 6px; }
.detail-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

.filter-block { display: flex; align-items: center; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.filter-label {
  font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  color: var(--text-muted); width: 56px; flex-shrink: 0;
}
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text-muted); padding: 6px 16px;
  border-radius: var(--radius); cursor: pointer; font-weight: 600; font-size: 13px;
  transition: background .15s, color .15s, border-color .15s;
}
.pill:hover { color: var(--text); }
.pill.active { background: var(--accent); color: #000; border-color: var(--accent); }

/* ── Sections ────────────────────────────────────────────── */
.detail-section {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
}
.detail-section h3 {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .8px; color: var(--text-muted); margin-bottom: 14px;
}
.hint { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--text-muted); }

/* ── Comparison table ────────────────────────────────────── */
.cmp-wrap { overflow-x: auto; }
table.cmp { width: 100%; border-collapse: collapse; font-size: 13px; }
table.cmp th {
  background: var(--bg2); border-bottom: 2px solid var(--border);
  padding: 8px 12px; text-align: right; font-weight: 700;
  color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
}
table.cmp th:first-child { text-align: left; }
table.cmp td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: right; }
table.cmp td:first-child { text-align: left; color: var(--text-muted); }
table.cmp tr:last-child td { border-bottom: none; }
table.cmp tr:hover td { background: rgba(255,255,255,.02); }
.val-strong { font-weight: 700; color: var(--text); }
.delta { font-weight: 700; font-size: 12px; }
.delta-pos { color: var(--win); }
.delta-neg { color: var(--loss); }
.delta-flat { color: var(--text-muted); }
.col-player { color: var(--accent) !important; }
.no-data { color: var(--text-muted); padding: 12px 0; font-style: italic; }

/* ── Champion image grid ─────────────────────────────────── */
.champ-img-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 12px;
}
.champ-card {
  position: relative;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  cursor: pointer; transition: border-color .15s, transform .1s;
}
.champ-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.champ-card.tier-top { border-color: var(--win); box-shadow: 0 0 0 1px var(--win); }
.champ-card.tier-bottom { border-color: var(--loss); box-shadow: 0 0 0 1px var(--loss); }
/* selection (orange) always overrides the tier ring */
.champ-card.active { border-color: var(--accent2); box-shadow: 0 0 0 1px var(--accent2); }

.tier-arrow {
  position: absolute; top: 6px; right: 6px;
  font-size: 12px; line-height: 1; font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .8); pointer-events: none;
}
.tier-arrow.up { color: var(--win); }
.tier-arrow.down { color: var(--loss); }
.champ-card img {
  width: 56px; height: 56px; border-radius: 8px; background: var(--bg);
  object-fit: cover;
}
.champ-card-name { font-size: 12px; font-weight: 700; text-align: center; }
.champ-card-games { font-size: 11px; color: var(--text-muted); }

/* ── Champion draft graph (VIN-20) ───────────────────────── */
.champ-back { margin-bottom: 14px; }
.champ-hero { display: flex; align-items: center; gap: 16px; }
.champ-hero-img {
  width: 64px; height: 64px; border-radius: 10px; background: var(--bg);
  object-fit: cover; border: 1px solid var(--border);
}
.graph-link {
  margin-left: 8px; background: none; border: 1px solid var(--border);
  color: var(--accent); font: inherit; font-size: 11px; font-weight: 700;
  text-transform: none; letter-spacing: 0; padding: 3px 10px;
  border-radius: 999px; cursor: pointer; transition: border-color .15s, background .15s;
}
.graph-link:hover { border-color: var(--accent); background: var(--bg3); }

/* Pairing detail: stacked When Ahead tables */
.pairing-wa { margin-top: 18px; }
.pairing-wa .wa-head {
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-muted); margin-bottom: 8px;
}
.pairing-wa .wa-sub-label {
  font-size: 12px; font-weight: 700; color: var(--accent);
  margin: 12px 0 4px;
}
.pairing-wa table.cmp { margin-bottom: 4px; }

.champ-stats { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.champ-stat {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 14px; min-width: 92px;
}
.champ-stat-label {
  font-size: 10px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: var(--text-muted);
}
.champ-stat-val { font-size: 18px; font-weight: 800; color: var(--text); }

/* ── SVG charts (charts.js) ──────────────────────────────── */
.chart-row {
  display: grid; grid-template-columns: minmax(0, 560px) auto;
  gap: 16px; align-items: start;
}
.chart-svg { width: 100%; height: auto; display: block; }
.chart-aside { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.chart-toggle {
  background: var(--bg3); border: 1px solid var(--border); color: var(--accent);
  font: inherit; font-size: 11px; font-weight: 700; white-space: nowrap;
  padding: 5px 12px; border-radius: 999px; cursor: pointer;
  transition: border-color .15s;
}
.chart-toggle:hover { border-color: var(--accent); }
.chart-side { width: 300px; max-width: 100%; }
.chart-side.hidden { display: none; }
.chart-side-table { width: 100%; font-size: 12px; }
.chart-side-table th, .chart-side-table td { white-space: nowrap; padding: 6px 8px; }
@media (max-width: 920px) {
  .chart-row { grid-template-columns: 1fr; }
  .chart-aside { align-items: stretch; }
}
.chart-dot { cursor: pointer; transition: r .1s ease; }
.chart-dot:hover { r: 8; }
.chart-tip {
  position: fixed; z-index: 200; pointer-events: none;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 7px 10px; font-size: 12px; line-height: 1.45; color: var(--text);
  white-space: nowrap;
}
.chart-tip.hidden { display: none; }
.chart-tip strong { color: var(--accent); font-weight: 700; }

.edge-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
.edge-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 12px;
  font: inherit; color: inherit; text-align: left; cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.edge-row:hover { border-color: var(--accent); transform: translateY(-1px); }
.edge-row img {
  width: 34px; height: 34px; border-radius: 6px; background: var(--bg); object-fit: cover;
}
.edge-name { font-weight: 700; font-size: 13px; flex: 1; }
.edge-weight { font-weight: 800; font-size: 14px; }
.edge-games { font-size: 11px; color: var(--text-muted); width: 56px; text-align: right; }

/* ── Match history ───────────────────────────────────────── */
.match-history { display: flex; flex-direction: column; gap: 10px; }
.match-card {
  background: var(--bg3); border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.match-card.win { border-left-color: var(--win); }
.match-card.loss { border-left-color: var(--loss); }

.match-top { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.result-tag {
  font-weight: 800; font-size: 12px; width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 5px; color: #fff;
}
.result-tag.win { background: var(--win); }
.result-tag.loss { background: var(--loss); }
.side-badge {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .04em;
}
.side-badge.side-blue { background: rgba(59,130,246,.18); color: #6ba5ff; }
.side-badge.side-red  { background: rgba(239,68,68,.18);  color: #ff7a7a; }
.match-teams { color: var(--text-muted); }
.match-teams em { font-style: normal; color: var(--text-muted); opacity: .7; margin: 0 4px; }

.match-mid { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.match-champ { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: 13px; }
.match-champ img {
  width: 36px; height: 36px; border-radius: 6px; background: var(--bg); object-fit: cover;
}
.match-champ.opp { color: var(--text-muted); }
.match-vs { color: var(--text-muted); font-size: 12px; }
.match-score { margin-left: auto; font-weight: 800; font-size: 15px; color: var(--text); }

.match-items { font-size: 12px; color: var(--text-muted); }
.match-items b { color: var(--text); font-weight: 700; }

/* clickable summary + expand affordance */
.match-summary { display: flex; flex-direction: column; gap: 8px; cursor: pointer; }
.match-summary:hover .match-chevron,
.match-card.expanded .match-chevron { color: var(--accent); }
.match-header { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-muted); }
.match-date { font-weight: 700; color: var(--text); }
.match-tournament { color: var(--text-muted); }
.match-chevron { margin-left: auto; transition: transform .15s, color .15s; }
.match-card.expanded .match-chevron { transform: rotate(180deg); }

/* expanded scoreboard */
.match-detail { display: flex; flex-direction: column; gap: 12px; margin-top: 10px;
  padding-top: 10px; border-top: 1px solid var(--border); }
.md-loading { color: var(--text-muted); font-style: italic; padding: 6px 0; }
.md-team { background: var(--bg); border: 1px solid var(--border);
  border-left: 3px solid var(--border); border-radius: var(--radius); padding: 8px 10px; }
.md-team.side-blue { border-left-color: #6ba5ff; }
.md-team.side-red  { border-left-color: #ff7a7a; }
.md-team-head { display: flex; align-items: center; gap: 10px; font-size: 13px;
  margin-bottom: 6px; flex-wrap: wrap; }
.md-teamname { font-weight: 700; }
.md-obj { margin-left: auto; color: var(--text-muted); font-size: 12px; }
.md-obj b { color: var(--text); }

table.md-board { width: 100%; border-collapse: collapse; font-size: 12px; }
table.md-board th { text-align: right; color: var(--text-muted); font-weight: 600;
  padding: 4px 8px; border-bottom: 1px solid var(--border); }
table.md-board th:first-child { text-align: left; }
table.md-board td { text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--border); }
table.md-board tr:last-child td { border-bottom: none; }
/* td.md-champ specificity must beat `table.md-board td { text-align:right }` */
table.md-board td.md-champ { display: flex; align-items: center; gap: 7px; text-align: left; }
.md-champ img { width: 26px; height: 26px; border-radius: 5px; background: var(--bg3); object-fit: cover; }
.md-names { display: flex; flex-direction: column; align-items: flex-start; text-align: left; line-height: 1.2; }
.md-pname { font-size: 12px; font-weight: 600; color: var(--text); }
.md-cname { font-size: 10.5px; font-weight: 500; color: var(--text-muted); }

/* highlight the player whose match history is being viewed */
.md-board tr.is-you td { background: rgba(88, 166, 255, .08); }
.md-board tr.is-you .md-pname { color: var(--accent); font-weight: 800; }
.md-board tr.is-you .md-cname { color: var(--text); }

/* ── Loading overlay ─────────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(13,17,23,.8); backdrop-filter: blur(4px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; z-index: 999;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-msg { font-size: 14px; color: var(--text-muted); }

/* ── 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: var(--text-muted); }

@media (max-width: 640px) {
  .filter-label { width: 100%; }
}
