:root {
  --bg: #050505;
  --panel: #0b0b0b;
  --gold: #d0a35a;
  --text: #f0e6d2;
  --muted: #b8a37e;
  --line: #7e5f2f;
  --row-left: #5b2613;
  --row-right: #4b1e11;
  --card: #131313;
  --avatar-bg: #2b2f35;
  --win: #7bbf6a;
  --lose: #c16c6c;
  --draw: #d0a35a;
}

* { box-sizing: border-box; }
html {
  scrollbar-gutter: stable;
}
body {
  margin: 0;
  font-family: "Rajdhani", "Noto Sans SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% 10%, #2a180d55 0%, transparent 45%),
    radial-gradient(circle at 80% 80%, #2a180d45 0%, transparent 45%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 28px 14px;
  animation: page-fade-in 520ms ease-out;
  overflow-y: scroll;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  border: 1px solid #5b4521;
  background: linear-gradient(180deg, #040404 0%, #090909 100%);
  padding: 18px;
}

.top-nav {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 10px;
}

.nav-link {
  display: inline-block;
  color: var(--gold);
  text-decoration: none;
  border: 1px solid #5b4521;
  padding: 6px 12px;
  background: linear-gradient(180deg, #15100a, #0c0905);
  transition: border-color 180ms ease, color 180ms ease, transform 180ms ease;
}

.nav-link:hover {
  border-color: #8a6431;
  color: #e6be79;
  transform: translateY(-1px);
}

h1 {
  margin: 0;
  text-align: center;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 1px;
  font-family: "Cinzel", "Noto Serif SC", "Times New Roman", serif;
}

.title-line {
  margin: 16px 0 20px;
  border-top: 2px solid var(--line);
  opacity: 0.9;
  transform-origin: center;
  animation: line-grow 700ms ease-out;
}

.mode-tabs {
  margin-top: 10px;
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-tab {
  display: inline-block;
  color: #ebdcc2;
  text-decoration: none;
  border: 1px solid #5b4521;
  padding: 5px 12px;
  background: linear-gradient(180deg, #15100a, #0c0905);
  transition: border-color 180ms ease, color 180ms ease, transform 180ms ease;
}

.mode-tab:hover {
  border-color: #8a6431;
  color: #f0c980;
  transform: translateY(-1px);
}

.mode-tab.active {
  color: var(--gold);
  border-color: #8a6431;
  box-shadow: inset 0 0 0 1px #2c1809;
}

.list-card {
  background: var(--panel);
  border: 1px solid #2a2a2a;
  min-height: 320px;
}

.match-list {
  margin: 0;
  padding: 10px;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.match-item {
  width: 100%;
  border: 1px solid #2f180d;
  background: linear-gradient(90deg, var(--row-left), var(--row-right));
  color: var(--text);
  cursor: pointer;
  padding: 10px 12px;
  text-align: left;
  transition: transform 220ms ease, box-shadow 220ms ease, border-color 220ms ease;
}

.match-item.enter {
  animation: item-in 420ms ease-out both;
  animation-delay: var(--delay, 0ms);
}

.match-item:hover {
  transform: translateY(-2px);
  border-color: #5f371f;
  box-shadow: 0 8px 22px #00000055;
}

.match-item.active {
  outline: 1px solid var(--gold);
  box-shadow: inset 0 0 0 1px #2c1809;
}

.match-detail {
  display: block;
  margin-top: 8px;
  padding: 0 10px;
  border: 1px solid #2a2a2a;
  background: #0d0d0d;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transform: translateY(-6px);
  transition: max-height 320ms ease, opacity 280ms ease, transform 280ms ease, padding 280ms ease;
}

.match-detail.show {
  max-height: 3200px;
  opacity: 1;
  transform: translateY(0);
  padding: 10px;
  overflow: auto;
}

.row-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  font-size: 19px;
  font-weight: 600;
}

.team {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.team-left {
  justify-self: start;
}

.team-right {
  justify-self: end;
  justify-content: flex-end;
}

.faction-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex: 0 0 28px;
}

.row-head .right { text-align: right; }
.score { color: #ead8b9; letter-spacing: 1px; }
.score {
  font-family: "Rajdhani", "Noto Sans SC", "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}
.score-win { color: var(--win); }
.score-lose { color: var(--lose); }
.score-draw { color: #ead8b9; }

.row-meta {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  font-family: "Rajdhani", "Noto Sans SC", "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

.detail-header {
  text-align: center;
  padding: 14px;
  border-bottom: 1px solid #2a2a2a;
}

.mode {
  color: var(--gold);
  font-size: 42px;
  margin: 0;
  line-height: 1;
  font-family: "Cinzel", "Noto Serif SC", "Times New Roman", serif;
}

.date {
  margin-top: 4px;
  color: var(--muted);
  font-size: 16px;
  font-family: "Rajdhani", "Noto Sans SC", "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

.result {
  margin-top: 2px;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
}

.players {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px;
}

.players section {
  min-width: 0;
}

table {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0 8px;
  font-size: 14px;
}

th, td {
  padding: clamp(4px, 0.8vw, 8px);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

th { color: #ebdcc2; font-weight: 600; }
td.num, th.num { text-align: center; width: 58px; }
td.num, th.num {
  font-family: "Rajdhani", "Noto Sans SC", "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

/* Allow long player names to wrap in match detail tables. */
.players table th:first-child,
.players table td:first-child {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.2;
}

tbody tr {
  background: linear-gradient(90deg, var(--row-left), var(--row-right));
  box-shadow: inset 0 0 0 1px #2f180d;
}

tbody tr td {
  background: transparent;
  border: 0;
}

.empty, .error {
  padding: 20px;
  text-align: center;
  color: var(--muted);
}

.load-more-status {
  padding: 8px 12px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.load-more-sentinel {
  height: 1px;
}

.leaderboard-card {
  background: var(--panel);
  border: 1px solid #2a2a2a;
  padding: 14px;
  overflow-x: auto;
}

.leaderboard-sort-mobile {
  display: none;
}

.leaderboard-table {
  border-spacing: 0 10px;
  font-size: 17px;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 10px 12px;
}

.leaderboard-table td.num,
.leaderboard-table th.num {
  width: 80px;
}

.rank {
  width: 72px;
  text-align: center;
}

.sort-btn {
  color: #ebdcc2;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  padding: 2px 6px;
  font: inherit;
}

.sort-btn:hover {
  color: var(--gold);
}

.sort-btn.active {
  color: var(--gold);
  border-color: #5b4521;
}

.back-to-top {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  border: 1px solid #5b4521;
  background: linear-gradient(180deg, #15100a, #0c0905);
  color: var(--gold);
  padding: 8px 12px;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 180ms ease, transform 180ms ease, border-color 180ms ease;
}

.back-to-top.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.back-to-top:hover {
  border-color: #8a6431;
  color: #e6be79;
}

.floating-query-btn {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 30;
  border: 1px solid #5b4521;
  background: linear-gradient(180deg, #15100a, #0c0905);
  color: var(--gold);
  padding: 8px 12px;
  text-decoration: none;
  transition: border-color 180ms ease, color 180ms ease, transform 180ms ease;
}

.floating-query-btn:hover {
  border-color: #8a6431;
  color: #e6be79;
  transform: translateY(-1px);
}

.query-card {
  background: var(--panel);
  border: 1px solid #2a2a2a;
  padding: 14px;
}

.query-form {
  display: grid;
  grid-template-columns: 1fr 180px auto;
  gap: 10px;
  margin-bottom: 14px;
}

.query-input {
  min-width: 0;
  background: #111;
  color: var(--text);
  border: 1px solid #3a2a16;
  padding: 10px;
  font: inherit;
}

.query-submit {
  border: 1px solid #5b4521;
  background: linear-gradient(180deg, #15100a, #0c0905);
  color: var(--gold);
  padding: 10px 14px;
  cursor: pointer;
  font: inherit;
}

.query-submit:hover {
  border-color: #8a6431;
  color: #e6be79;
}

.query-summary {
  margin-bottom: 12px;
  color: #ebdcc2;
}

.query-summary strong {
  color: var(--gold);
}

.query-player-name {
  text-align: center;
  color: var(--gold);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 6px;
}

.query-player-total {
  text-align: center;
  color: #ebdcc2;
  font-size: 16px;
}

.query-result-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
  font-size: 14px;
}

.query-result-table th,
.query-result-table td {
  padding: 8px 10px;
}

.query-result-table td.num,
.query-result-table th.num {
  text-align: center;
  width: 72px;
  font-family: "Rajdhani", "Noto Sans SC", "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

.query-result-table th.score-col,
.query-result-table td.score-col {
  width: 130px;
  text-align: left;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
  font-family: "Rajdhani", "Noto Sans SC", "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

.query-result-table th.mode-col,
.query-result-table td.mode-col {
  width: 96px;
  text-align: left;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}

.query-result-table th.result-col,
.query-result-table td.result-col {
  width: 96px;
  text-align: left;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}

.query-result-table th.team-col,
.query-result-table td.team-col {
  width: 84px;
  text-align: left;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}

.query-match-list {
  padding: 0;
}

.query-match-item {
  padding: 10px 12px;
}

.query-match-detail {
  padding: 0 10px;
}

.query-match-detail tr.focus-player {
  box-shadow: inset 0 0 0 1px #b48742;
}

.query-match-detail tr.focus-player td:first-child {
  color: var(--gold);
  font-weight: 700;
}

.error { color: #cf7878; }

.admin-wrap {
  max-width: 1200px;
}

.admin-card {
  margin-bottom: 12px;
}

.admin-hidden {
  display: none;
}

.admin-login-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.admin-status {
  margin-top: 10px;
  color: var(--muted);
}

.admin-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.admin-filter-form {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr 150px auto;
  gap: 10px;
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-players-table {
  width: 100%;
  min-width: 820px;
  border-spacing: 0 8px;
}

.admin-op-btn {
  padding: 6px 10px;
  min-width: 68px;
}

.admin-players-table th:last-child,
.admin-players-table td:last-child {
  width: 120px;
  text-align: left;
  padding-right: 12px;
}

.admin-paging {
  margin-top: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

@keyframes page-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes line-grow {
  from {
    transform: scaleX(0.3);
    opacity: 0;
  }
  to {
    transform: scaleX(1);
    opacity: 0.9;
  }
}

@keyframes item-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
