/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --gold:      #c89b3c;
  --gold-light:#e8c76b;
  --dark-bg:   #0a0e1a;
  --panel-bg:  #0f1728;
  --card-bg:   #131c32;
  --border:    #1e2d4a;
  --adc-color: #4fc3f7;
  --sup-color: #ce93d8;
  --win-color: #4caf50;
  --loss-color:#ef5350;
  --text:      #c8d0e0;
  --text-dim:  #6b7a9a;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--dark-bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  padding: 1rem 1.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #06091a 0%, var(--dark-bg) 100%);
  flex-shrink: 0;
}

.header-body {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 0.75rem;
}

.header-left {
  width: 50%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.header-right {
  width: 50%;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.stats-panel-title {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}


.subtitle {
  color: var(--text-dim);
  font-size: 1rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin: 0;
}

/* ── Player Cards Row ── */
.players {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 1rem;
}

.player-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 1rem 1.5rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  width: 170px;
  transition: border-color 0.2s;
}

.adc-card { border-color: rgba(79,195,247,0.3); }
.sup-card { border-color: rgba(206,147,216,0.3); }

.role-badge {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
}

.adc-badge { background: rgba(79,195,247,0.15); color: var(--adc-color); border: 1px solid rgba(79,195,247,0.3); }
.sup-badge { background: rgba(206,147,216,0.15); color: var(--sup-color); border: 1px solid rgba(206,147,216,0.3); }

.player { font-size: 1.15rem; font-weight: 700; }
.adc-player { color: var(--adc-color); }
.sup-player { color: var(--sup-color); }
.player .tag { opacity: 0.55; font-weight: 400; font-size: 0.8em; }

.direction-tag {
  font-size: 0.78rem;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}
.dir-arrow { color: var(--gold); }

/* ── Challenge Emblem (center) ── */
.challenge-emblem {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  flex-shrink: 0;
}

.emblem-top, .emblem-bot {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--gold);
  opacity: 0.7;
}

.emblem-vs {
  font-size: 1.8rem;
  line-height: 1;
  filter: drop-shadow(0 0 8px rgba(200,155,60,0.5));
}

/* ── Stats Bar ── */
.stats-bar {
  display: flex;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.stat-item {
  flex: 1;
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  border-right: 1px solid var(--border);
}
.stat-item:last-child { border-right: none; }

.stat-value {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--gold-light);
  line-height: 1;
}
.stat-value.win-pct-val { color: var(--win-color); }
.stat-value.loss-val    { color: var(--loss-color); }

.stat-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

/* ── Progress Bar ── */
.challenge-progress {
  width: 100%;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
  letter-spacing: 0.05em;
}

.progress-labels .pct-label {
  color: var(--gold-light);
  font-weight: 700;
}

.progress-track {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--gold) 0%, var(--gold-light) 100%);
  transition: width 0.6s ease;
}

/* ── Main ── */
main {
  flex: 1;
  overflow-y: auto;
  width: 100%;
}

/* Inner content wrapper keeps things centred */
main > * {
  max-width: 700px;
  margin-left: auto;
  margin-right: auto;
  padding: 0 1rem;
}

/* ── Loading ── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 4rem 0;
  color: var(--text-dim);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ── Error ── */
.error-msg {
  background: rgba(239,83,80,0.1);
  border: 1px solid var(--loss-color);
  border-radius: 8px;
  padding: 1.2rem;
  text-align: center;
  color: var(--loss-color);
}

.hidden { display: none !important; }

/* ── Ladder ── */
.ladder {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-top: 2rem;
  padding-bottom: 2rem;
}

/* connector line between rounds */
.round-connector {
  display: flex;
  justify-content: center;
  height: 24px;
  position: relative;
}
.round-connector::before {
  content: '';
  position: absolute;
  width: 2px;
  top: 0; bottom: 0;
  background: linear-gradient(180deg, var(--border) 0%, var(--gold) 50%, var(--border) 100%);
}
.round-connector .step-label {
  background: var(--dark-bg);
  color: var(--text-dim);
  font-size: 0.65rem;
  padding: 0 0.4rem;
  z-index: 1;
  align-self: center;
}

/* ── Round Card ── */
.round-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  position: relative;
  transition: border-color 0.2s;
}

.round-card.current {
  border-color: var(--gold);
  box-shadow: 0 0 30px rgba(200,155,60,0.15), inset 0 0 30px rgba(200,155,60,0.03);
}

.round-card.completed {
  opacity: 0.75;
}

.round-card.played_ahead {
  border-color: rgba(255,167,38,0.5);
  box-shadow: 0 0 16px rgba(255,167,38,0.08);
}

.round-card.upcoming {
  opacity: 0.35;
}

.round-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.round-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}

.round-status {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
}

.round-status.win {
  background: rgba(76,175,80,0.15);
  color: var(--win-color);
  border: 1px solid rgba(76,175,80,0.3);
}

.round-status.current-badge {
  background: rgba(200,155,60,0.15);
  color: var(--gold-light);
  border: 1px solid rgba(200,155,60,0.4);
  animation: pulse-border 2s ease-in-out infinite;
}

.round-status.skip-badge {
  background: rgba(255,167,38,0.15);
  color: #ffa726;
  border: 1px solid rgba(255,167,38,0.4);
}

.round-status.upcoming-badge {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  font-weight: 500;
}

@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 0 rgba(200,155,60,0.4); }
  50%       { box-shadow: 0 0 0 4px rgba(200,155,60,0); }
}

/* ── Champions Row ── */
.champions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.champion {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.champion.adc-side .letter-badge { border-color: var(--adc-color); color: var(--adc-color); }
.champion.sup-side .letter-badge { border-color: var(--sup-color); color: var(--sup-color); }

.portrait-wrap {
  position: relative;
  width: 80px;
  height: 80px;
}

.round-card.current .portrait-wrap { width: 96px; height: 96px; }

.portrait-wrap img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
  border: 2px solid var(--border);
  display: block;
  background: var(--panel-bg);
}

.champion.adc-side .portrait-wrap img { border-color: var(--adc-color); }
.champion.sup-side .portrait-wrap img { border-color: var(--sup-color); }
.round-card.current .portrait-wrap img { border-width: 3px; }

.letter-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid;
  background: var(--dark-bg);
  font-size: 0.7rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.champ-name {
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  color: var(--text);
  max-width: 100px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-name {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-align: center;
}

.vs-divider {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-dim);
  flex-shrink: 0;
}

/* ── Losses ── */
.losses-row {
  margin-top: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.loss-icons {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.loss-icon {
  width: 12px;
  height: 12px;
  background: var(--loss-color);
  border-radius: 2px;
  opacity: 0.85;
}

.losses-text {
  font-size: 0.78rem;
  color: var(--text-dim);
}
.losses-text strong { color: var(--loss-color); }

.no-losses {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-style: italic;
}

/* ── Game History Dropdown ── */
.game-history {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.game-history-toggle {
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
}
.game-history-toggle::-webkit-details-marker { display: none; }
.game-history-toggle::before {
  content: '▶';
  font-size: 0.6rem;
  transition: transform 0.15s;
}
details[open] .game-history-toggle::before {
  transform: rotate(90deg);
}
.game-history-toggle:hover { color: var(--text); }

.game-count {
  background: var(--border);
  color: var(--text-dim);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 99px;
}

.game-entries {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.game-entry {
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
}
.game-entry.game-win  { border-color: rgba(76,175,80,0.25); }
.game-entry.game-loss { border-color: rgba(239,83,80,0.2);  }

.game-entry-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.75rem;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
}

.game-entry-num {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

.game-entry-players {
  display: flex;
  align-items: stretch;
}

.game-player-stats {
  flex: 1;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.game-entry-divider {
  width: 1px;
  background: var(--border);
  flex-shrink: 0;
}

.gps-name {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.adc-side .gps-name { color: var(--adc-color); }
.sup-side .gps-name { color: var(--sup-color); }

.gps-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.5rem;
}

.gps-stat {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.gps-val {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.gps-lbl {
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.result-badge {
  font-size: 0.65rem;
  font-weight: 800;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}
.result-badge.win  { background: rgba(76,175,80,0.2);  color: var(--win-color);  }
.result-badge.loss { background: rgba(239,83,80,0.2); color: var(--loss-color); }

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-dim);
}
.empty-state h2 { color: var(--gold); margin-bottom: 0.5rem; }

/* ── Footer ── */
footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.refresh-btn {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--card-bg);
  border: 1px solid var(--gold);
  color: var(--gold);
  padding: 0.5rem 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transition: background 0.15s;
  z-index: 50;
}
.refresh-btn:hover { background: rgba(200,155,60,0.1); }
.refresh-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.last-updated { font-size: 0.68rem; color: var(--text-dim); display: block; text-align: center; margin-top: 0.35rem; }

/* ── Responsive ── */
@media (max-width: 790px) {
  .header-body {
    flex-direction: column;
    gap: 1rem;
  }
  .header-left,
  .header-right {
    width: 100%;
  }
  .header-left {
    align-items: center;
  }
  .players {
    justify-content: center;
  }
  .stats-bar { width: 100%; }
  .challenge-progress { width: 100%; }

  .player-card { min-width: 115px; padding: 0.75rem 0.9rem; }
  .player { font-size: 0.92rem; }
  .challenge-emblem { gap: 0; }
  .emblem-vs { font-size: 1.3rem; }
  .stat-value { font-size: 0.95rem; }
  .round-card { padding: 1rem; }
  .portrait-wrap { width: 64px; height: 64px; }
  .round-card.current .portrait-wrap { width: 80px; height: 80px; }
  .champ-name { font-size: 0.72rem; }
}
