:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0c0d12;
  color: #f2f3f5;
}

* { box-sizing: border-box; }
html { min-height: 100%; scrollbar-gutter: stable; }
body {
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(circle at 30% 8%, rgba(88, 101, 242, 0.18), transparent 34rem), #0c0d12;
}
button, input { font: inherit; }

.report-page { padding: clamp(1.5rem, 4vw, 3rem); }
.report-shell { width: min(100%, 96rem); margin: 0 auto; }
.page-header { margin-bottom: 1.5rem; }
.page-title { margin: 0; font-size: clamp(2.2rem, 6vw, 3.4rem); letter-spacing: -0.05em; }
.page-loading, .page-error, .empty-state { color: #949ba4; }
.page-loading { display: grid; min-height: 45vh; place-items: center; }
.page-error { padding: 1rem; border: 1px solid #4d3037; border-radius: 0.85rem; background: #2d171c; color: #ffb4bc; }
[hidden] { display: none !important; }

.panel {
  min-width: 0;
  padding: 1.2rem;
  border: 1px solid #292b35;
  border-radius: 1rem;
  background: rgba(24, 25, 32, 0.94);
}

.game-badge {
  display: inline-grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(3, 1.15rem);
  grid-auto-rows: 1.15rem;
  align-content: center;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  width: 4.9rem;
  min-height: 2.55rem;
  padding: 0.45rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0.65rem;
  background: var(--game-bg, #5865f2);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);
}
.game-badge > span {
  display: flex;
  width: 1.15rem;
  height: 1.15rem;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.game-badge .bi {
  display: inline-flex;
  width: 1.15rem;
  height: 1.15rem;
  align-items: center;
  justify-content: center;
  color: var(--icon-color, #f2f3f5);
  font-size: 1.08rem;
  line-height: 1;
}
.game-badge .bi::before { display: block; line-height: 1; }

.player-label { min-width: 0; }
.player-display { display: block; overflow-wrap: anywhere; font-weight: 800; }
.player-actual { display: block; margin-top: 0.1rem; color: #777e89; font-size: 0.76rem; }
.name-list { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.name-chip {
  min-width: 0;
  padding: 0.4rem 0.6rem;
  border: 1px solid #343640;
  border-radius: 0.55rem;
  background: #202129;
}

/* History */
.history-list { display: grid; gap: 0.75rem; }
.history-card {
  padding: 0;
  overflow: hidden;
  transition: border-color 120ms ease, background 120ms ease;
}
.history-card:hover, .history-card.expanded { border-color: #5865f2; }
.history-card-header { display: flex; align-items: stretch; min-width: 0; }
.history-summary {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(14rem, 1.1fr) minmax(11rem, 0.75fr) minmax(11rem, 0.75fr) auto;
  gap: 1rem;
  width: 100%;
  padding: 1rem 1.15rem;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
}
.history-entry-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-right: 1rem;
}
.history-edit-trigger,
.history-delete-trigger {
  align-self: center;
  min-height: 2.35rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid #3a3c47;
  border-radius: 0.65rem;
  background: #2b2d31;
  color: #f2f3f5;
  cursor: pointer;
  font-weight: 850;
}
.history-edit-trigger:hover { border-color: #5865f2; background: #35373c; }
.history-delete-trigger { border-color: #7f2f39; background: #5c242c; color: #ffe7ea; }
.history-delete-trigger:hover { background: #71313b; }
.history-edit-trigger:disabled,
.history-delete-trigger:disabled { cursor: wait; opacity: 0.65; }
.history-event { display: flex; align-items: center; gap: 0.8rem; min-width: 0; }
.history-event-text { min-width: 0; }
.history-title { display: block; overflow-wrap: anywhere; font-weight: 900; }
.history-subtitle { display: block; margin-top: 0.15rem; overflow-wrap: anywhere; color: #b5bac1; font-size: 0.85rem; line-height: 1.35; }
.history-date { display: block; margin-top: 0.2rem; color: #949ba4; font-size: 0.8rem; }
.history-field { min-width: 0; }
.history-label { display: block; margin-bottom: 0.35rem; color: #777e89; font-size: 0.72rem; font-weight: 850; letter-spacing: 0.05em; text-transform: uppercase; }
.history-value { overflow-wrap: anywhere; color: #dbdee1; }
.history-player-link,
.history-participant-link { color: inherit; text-decoration: none; }
.history-player-link:hover,
.history-participant-link:hover { color: #b8c0ff; text-decoration: underline; }
.history-participant-link { display: inline-flex; }
.participant-count { align-self: center; color: #b5bac1; font-size: 0.88rem; white-space: nowrap; }
.history-details { padding: 0 1.15rem 1.15rem; border-top: 1px solid #292b35; }
.history-details-title { margin: 1rem 0 0.65rem; font-size: 0.9rem; }
.history-bracket { min-width: 0; }
.history-bracket-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.history-bracket-meta { margin: -0.35rem 0 0.7rem; color: #949ba4; font-size: 0.8rem; }
.history-bracket-stage {
  --history-bracket-row-height: 7.4rem;
  --history-bracket-row-gap: 0.65rem;
  display: flex;
  gap: 1rem;
  min-width: 0;
  overflow-x: auto;
  padding: 0.75rem;
  border: 1px solid #30323b;
  border-radius: 0.85rem;
  background: rgba(12, 13, 18, 0.56);
}
.history-bracket-round {
  display: grid;
  flex: 0 0 16rem;
  align-content: start;
  gap: 0.55rem;
  min-width: 14rem;
}
.history-bracket-round-title {
  margin: 0;
  color: #949ba4;
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.history-bracket-matches {
  display: grid;
  grid-template-rows: repeat(var(--history-bracket-base-matches, 1), var(--history-bracket-row-height));
  row-gap: var(--history-bracket-row-gap);
}
.history-bracket-match {
  display: grid;
  align-self: center;
  gap: 0.35rem;
  padding: 0.55rem;
  border: 1px solid #30323b;
  border-radius: 0.75rem;
  background: #17181e;
}
.history-bracket-match-label {
  color: #777e89;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.history-bracket-slot {
  display: grid;
  gap: 0.12rem;
  min-width: 0;
  padding: 0.45rem 0.55rem;
  border: 1px solid #353741;
  border-left: 3px solid var(--bracket-entry-color, #4f3961);
  border-radius: 0.6rem;
  background: #202127;
}
.history-bracket-slot.winner { border-color: #64bd8b; background: rgba(45, 111, 76, 0.43); }
.history-bracket-slot.empty { border-style: dashed; border-left-width: 1px; color: #777e89; background: transparent; }
.history-bracket-slot-line { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; min-width: 0; }
.history-bracket-entry-name { overflow: hidden; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.history-bracket-score { flex: 0 0 auto; color: #f2f3f5; font-weight: 900; }
.history-bracket-members { overflow: hidden; color: #b5bac1; font-size: 0.72rem; text-overflow: ellipsis; white-space: nowrap; }
.history-edit-backdrop {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(4, 5, 8, 0.78);
  backdrop-filter: blur(7px);
}
.history-edit-dialog {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(72rem, 100%);
  max-height: min(54rem, calc(100vh - 2rem));
  overflow: hidden;
  border: 1px solid #3a3c47;
  border-radius: 1rem;
  background: #181920;
  box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.55);
}
.history-edit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid #30323b;
}
.history-edit-title { margin: 0; font-size: 1.25rem; }
.history-edit-close {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  border: 1px solid #3a3c47;
  border-radius: 0.65rem;
  background: #2b2d31;
  color: #f2f3f5;
  cursor: pointer;
  font-size: 1.2rem;
}
.history-edit-form { min-height: 0; overflow: auto; padding: 1.2rem; }
.history-edit-top-fields { display: grid; grid-template-columns: 1.2fr 1fr 0.8fr; gap: 0.75rem; }
.history-edit-description-field { margin-top: 0.75rem; }
.history-edit-description { min-height: 4.8rem; line-height: 1.4; resize: vertical; }
.history-edit-field { display: grid; gap: 0.4rem; }
.history-edit-label { color: #dbdee1; font-size: 0.82rem; font-weight: 850; }
.history-edit-input,
.history-edit-search {
  width: 100%;
  min-height: 2.65rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid #3a3c47;
  border-radius: 0.65rem;
  background: #111218;
  color: #f2f3f5;
}
.history-edit-pickers { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.75rem; margin-top: 1rem; }
.history-edit-picker {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  padding: 0.75rem;
  border: 1px solid #30323b;
  border-radius: 0.8rem;
  background: #111218;
}
.history-edit-picker-heading { display: flex; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.55rem; }
.history-edit-count {
  position: relative;
  color: #949ba4;
  cursor: help;
  font-size: 0.78rem;
  white-space: nowrap;
}
.history-edit-selection-tooltip {
  position: absolute;
  z-index: 5;
  right: 0;
  bottom: calc(100% + 0.5rem);
  display: none;
  width: max-content;
  max-width: min(22rem, 70vw);
  max-height: 12rem;
  overflow: auto;
  padding: 0.6rem 0.7rem;
  border: 1px solid #3a3c47;
  border-radius: 0.65rem;
  background: #202129;
  box-shadow: 0 0.8rem 2rem rgba(0, 0, 0, 0.38);
  color: #f2f3f5;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: normal;
}
.history-edit-count:hover .history-edit-selection-tooltip,
.history-edit-count:focus .history-edit-selection-tooltip { display: block; }
.history-edit-options { display: grid; align-content: start; gap: 0.35rem; max-height: 18rem; overflow: auto; margin-top: 0.55rem; padding-right: 0.2rem; }
.history-edit-player {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  padding: 0.5rem 0.6rem;
  border: 1px solid transparent;
  border-radius: 0.6rem;
  background: #181920;
  cursor: pointer;
}
.history-edit-player:hover, .history-edit-player.selected { border-color: #5865f2; background: rgba(88, 101, 242, 0.16); }
.history-edit-player input { flex: 0 0 auto; accent-color: #5865f2; }
.history-edit-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1rem; }
.history-edit-button {
  min-height: 2.6rem;
  padding: 0.6rem 0.9rem;
  border: 1px solid #3a3c47;
  border-radius: 0.65rem;
  background: #2b2d31;
  color: #f2f3f5;
  cursor: pointer;
  font-weight: 850;
}
.history-edit-button.primary { border-color: #5865f2; background: #5865f2; }
.history-edit-button:disabled { cursor: wait; opacity: 0.65; }
.history-edit-status { min-height: 1.2rem; margin: 0.8rem 0 0; color: #949ba4; }
.history-edit-status.error { color: #ff8b96; }

/* Leaderboard */
.leaderboard-layout { display: grid; grid-template-columns: minmax(15rem, 19rem) minmax(0, 1fr); gap: 1rem; align-items: start; }
.filter-panel { position: sticky; top: 1rem; }
.filter-title { margin: 0 0 0.8rem; font-size: 1rem; }
.game-filter-list { display: grid; gap: 0.45rem; max-height: calc(100vh - 14rem); overflow: auto; padding-right: 0.2rem; }
.game-filter {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  min-height: 3rem;
  padding: 0.55rem;
  border: 1px solid transparent;
  border-radius: 0.7rem;
  background: #111218;
  color: #dbdee1;
  cursor: pointer;
  font-weight: 750;
  text-align: left;
}
.game-filter:hover, .game-filter.active { border-color: #5865f2; background: rgba(88, 101, 242, 0.16); color: #fff; }
.game-filter.all { padding-left: 0.85rem; }
.game-filter .game-badge { transform: scale(0.78); margin: -0.25rem -0.4rem -0.25rem -0.3rem; }
.leaderboard-heading { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.leaderboard-heading h2 { margin: 0; font-size: 1.25rem; }
.table-wrap { overflow-x: auto; }
.leaderboard-table { width: 100%; border-collapse: collapse; }
.leaderboard-table th, .leaderboard-table td { padding: 0.85rem; border-bottom: 1px solid #292b35; text-align: left; }
.leaderboard-table th { padding-block: 0.45rem; }
.sort-button {
  padding: 0.35rem 0;
  border: 0;
  background: transparent;
  color: #949ba4;
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.sort-button::after { content: ""; margin-left: 0.35rem; }
.sort-button.active::after { content: attr(data-arrow); color: #b8c0ff; }
.sort-button:hover, .sort-button.active { color: #f2f3f5; }
.rank { width: 3rem; color: #777e89; font-weight: 800; }
.player-link { color: #f2f3f5; text-decoration: none; }
.player-link:hover { color: #b8c0ff; text-decoration: underline; }
.numeric { font-variant-numeric: tabular-nums; }

@media (min-width: 48.0625rem) {
  html.leaderboard-document {
    height: 100%;
    overflow: hidden;
    scrollbar-gutter: auto;
  }
  .leaderboard-page-body {
    height: 100vh;
    min-height: 0;
    overflow: hidden;
  }
  .leaderboard-page-body .report-page {
    height: calc(100vh - 4.25rem);
    min-height: 0;
    overflow: hidden;
  }
  .leaderboard-page-body .report-shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
  }
  .leaderboard-page-body .leaderboard-layout {
    flex: 1 1 auto;
    align-items: stretch;
    min-height: 0;
    overflow: hidden;
  }
  .leaderboard-page-body .filter-panel,
  .leaderboard-page-body .leaderboard-panel {
    position: static;
    display: grid;
    min-height: 0;
    overflow: hidden;
  }
  .leaderboard-page-body .filter-panel {
    grid-template-rows: auto minmax(0, 1fr);
  }
  .leaderboard-page-body .leaderboard-panel {
    grid-template-rows: auto minmax(0, 1fr);
  }
  .leaderboard-page-body .game-filter-list {
    max-height: none;
    min-height: 0;
    overflow-y: auto;
  }
  .leaderboard-page-body .table-wrap {
    min-height: 0;
    overflow: auto;
  }
  .leaderboard-page-body .leaderboard-table thead th {
    position: sticky;
    z-index: 1;
    top: 0;
    background: #191a20;
  }
}

/* Player profile */
.profile-back { display: inline-block; margin-bottom: 1rem; color: #b8c0ff; text-decoration: none; }
.profile-back:hover { text-decoration: underline; }
.profile-name { margin: 0; font-size: clamp(2.2rem, 6vw, 3.4rem); letter-spacing: -0.05em; }
.profile-real-name { margin: 0.3rem 0 0; color: #949ba4; }
.profile-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.75rem; margin: 1.5rem 0; }
.stat-card { padding: 1rem; border: 1px solid #292b35; border-radius: 0.85rem; background: #181920; }
.stat-label { display: block; margin-bottom: 0.25rem; color: #777e89; font-size: 0.74rem; font-weight: 850; letter-spacing: 0.05em; text-transform: uppercase; }
.stat-value { font-size: 1.5rem; font-weight: 900; }
.profile-highlights { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.highlight-title { margin: 0 0 0.8rem; color: #949ba4; font-size: 0.82rem; letter-spacing: 0.05em; text-transform: uppercase; }
.highlight-game { display: flex; align-items: center; gap: 0.8rem; }
.highlight-name { font-size: 1.05rem; font-weight: 900; }
.highlight-stats { margin-top: 0.2rem; color: #b5bac1; font-size: 0.86rem; }
.profile-history-title { margin: 1.75rem 0 0.8rem; }
.profile-history { display: grid; gap: 0.6rem; }
.profile-result { display: block; padding: 0; overflow: hidden; }
.profile-result.winner { border-color: #3f8c61; background: rgba(37, 91, 60, 0.42); }
.profile-result.runner-up { border-color: #bd7434; background: rgba(121, 70, 29, 0.42); }
.profile-result-summary {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: 100%;
  padding: 1rem;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
}
.profile-result-main { min-width: 0; flex: 1; }
.profile-result-title { display: block; font-weight: 850; }
.profile-result-subtitle { display: block; margin-top: 0.12rem; color: #b5bac1; font-size: 0.82rem; line-height: 1.35; }
.profile-result-date { color: #949ba4; font-size: 0.8rem; }
.profile-result-indicator { flex: 0 0 auto; color: #b5bac1; font-size: 1.25rem; font-weight: 900; }
.profile-result-details {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  padding: 1rem;
  border-top: 1px solid rgba(148, 155, 164, 0.25);
}
.profile-result-meta { grid-column: 1 / -1; margin: 0; color: #b5bac1; font-size: 0.85rem; }
.profile-result-group { min-width: 0; }
.profile-result-group-title { margin: 0 0 0.5rem; color: #b5bac1; font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; }
.profile-result-people { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.profile-detail-player {
  display: inline-grid;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  border: 1px solid #3a3c47;
  border-radius: 0.6rem;
  background: rgba(17, 18, 24, 0.72);
  color: #f2f3f5;
  text-decoration: none;
}
.profile-detail-player:hover { border-color: #8e69a6; color: #ffffff; }
.profile-detail-player.current-player { border-color: #c5a5d8; box-shadow: 0 0 0 2px rgba(142, 105, 166, 0.3); }
.outcome {
  flex: 0 0 auto;
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  background: #2b2d31;
  color: #b5bac1;
  font-size: 0.75rem;
  font-weight: 850;
  text-transform: capitalize;
}
.outcome.winner { background: #183c2a; color: #7ee2a8; }
.outcome.runner-up { background: #3a321b; color: #f6d365; }

button:focus-visible, a:focus-visible { outline: 2px solid #5865f2; outline-offset: 2px; }

@media (max-width: 64rem) {
  .history-summary { grid-template-columns: minmax(14rem, 1fr) repeat(2, minmax(9rem, 0.7fr)); }
  .participant-count { grid-column: 1 / -1; }
}

@media (max-width: 48rem) {
  .leaderboard-layout { grid-template-columns: 1fr; }
  .filter-panel { position: static; }
  .game-filter-list { display: flex; max-height: none; overflow-x: auto; }
  .game-filter { flex: 0 0 auto; width: auto; max-width: 15rem; }
  .history-summary { grid-template-columns: 1fr; }
  .participant-count { grid-column: auto; }
  .profile-summary, .profile-highlights { grid-template-columns: 1fr; }
  .profile-result-details { grid-template-columns: 1fr; }
  .history-edit-top-fields, .history-edit-pickers { grid-template-columns: 1fr; }
  .history-edit-options { max-height: 12rem; }
}

@media (max-width: 34rem) {
  .report-page { padding-inline: 1rem; }
  .leaderboard-table th, .leaderboard-table td { padding-inline: 0.55rem; }
  .leaderboard-table .played-column { display: none; }
  .history-card-header { align-items: center; }
  .history-entry-actions { margin-right: 0.7rem; }
}
