:root {
  --bg: #0b0d10;
  --panel: #141311;
  --panel-alt: #1c1a16;
  --border: #2c2822;
  --row: #151a21;
  --row-border: #2a3038;
  --gold: #d4af37;
  --gold-soft: #f5d876;
  --silver: #c7ccd6;
  --bronze: #cd7f32;
  --text: #f0ede6;
  --text-dim: #a39a8a;
  --accent: #e8a33d;
  --win: #34d399;
  --gold-text: linear-gradient(180deg, #fbe7a6 0%, #e7b955 50%, #b9832a 100%);
  --font-display: 'Rajdhani', sans-serif;
  --font-title: 'Montserrat', 'Inter', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  position: relative;
  overflow-x: hidden;
}

.bg-glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background:
    radial-gradient(ellipse 900px 500px at 50% 0%, rgba(40, 46, 56, 0.55), transparent 70%),
    linear-gradient(180deg, #111419 0%, #090a0d 100%);
}

/* Negative inset stops the blur fading the edges to transparent */
.bg-image {
  position: absolute;
  inset: -30px;
  background: url('../assets/background.png') center / cover no-repeat;
  filter: blur(5px);
  opacity: 0.4;
}

/* Thin gold diagonals in the top corners */
.bg-glow::before,
.bg-glow::after {
  content: '';
  position: absolute;
  top: -40px;
  width: 1.5px;
  height: 420px;
  background: linear-gradient(180deg, rgba(212, 175, 55, 0.9), rgba(212, 175, 55, 0));
}

.bg-glow::before { left: 12%; transform: rotate(35deg); transform-origin: top; }
.bg-glow::after { right: 12%; transform: rotate(-35deg); transform-origin: top; }

.bg-suit {
  position: absolute;
  top: 40px;
  font-size: 180px;
  line-height: 1;
  color: #1b1f26;
  text-shadow: 0 0 30px rgba(0, 0, 0, 0.6);
}

.bg-suit-left { left: calc(50% - 470px); }
.bg-suit-right { right: calc(50% - 470px); }

.page-header {
  padding: 10px 24px 0;
  text-align: center;
}

.chip-suit {
  display: inline-block;
  font-size: 44px;
  line-height: 1;
  background: var(--gold-text);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.chip-suit img {
  display: block;
  height: 40px;
  width: 40px;
  object-fit: contain;
  border-radius: 50%;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.title-rule {
  flex: 0 1 260px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold));
}

.title-rule:last-child {
  background: linear-gradient(90deg, var(--gold), transparent);
}

h1 {
  font-family: var(--font-title);
  font-weight: 900;
  font-size: clamp(30px, 4.5vw, 54px);
  line-height: 1;
  white-space: nowrap;
  letter-spacing: 1px;
  margin: 0;
  text-transform: uppercase;
  background: var(--gold-text);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.6));
}

.subtitle {
  margin: 8px 0 0;
  font-family: var(--font-title);
  font-weight: 600;
  font-size: clamp(13px, 1.8vw, 20px);
  letter-spacing: 0.65em;
  padding-left: 0.65em;
  text-transform: uppercase;
  color: #e9d6a6;
}

.header-stats {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 12px;
}

.header-stats:empty { display: none; }

.hstat {
  text-align: center;
}

.hstat .val {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--gold-soft);
}

.hstat .lbl {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.board-wrap {
  max-width: 1000px;
  margin: 8px auto 0;
  padding: 0 24px;
}

/* Dark panel behind the table so the background is muted in the gaps between rows */
.board-card {
  background: rgba(8, 10, 13, 0.82);
  border-radius: 14px;
  padding: 0 8px;
}

table.leaderboard {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 6px;
}

/* Each row is its own rounded card: borders on cells, rounded at the ends */
.leaderboard th,
.leaderboard td {
  background: var(--row);
  border-top: 1px solid var(--row-border);
  border-bottom: 1px solid var(--row-border);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.leaderboard th:first-child,
.leaderboard td:first-child {
  border-left: 1px solid var(--row-border);
  border-radius: 10px 0 0 10px;
}

.leaderboard th:last-child,
.leaderboard td:last-child {
  border-right: 1px solid var(--row-border);
  border-radius: 0 10px 10px 0;
}

.leaderboard thead th {
  background: linear-gradient(180deg, #1a1f27, #11151b);
  text-align: center;
  font-family: var(--font-title);
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: #e6e8ec;
  font-weight: 700;
  padding: 6px 12px;
  height: clamp(44px, 6.5vh, 60px);
}

.leaderboard .col-num, .leaderboard .col-rank {
  text-align: center;
}

.leaderboard .col-rank { width: 11%; }
.leaderboard .col-name { width: 32%; }

.leaderboard thead .col-name { color: #b9bec7; }

.leaderboard .col-icon svg {
  width: 40px;
  height: 32px;
  vertical-align: middle;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.leaderboard tbody tr {
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.15s ease;
  opacity: 0;
  transform: translateY(8px);
  animation: rowIn 0.4s ease forwards;
}

.leaderboard tbody tr:hover {
  filter: brightness(1.18);
}

.leaderboard tbody tr:active {
  transform: scale(0.997);
}

@keyframes rowIn {
  to { opacity: 1; transform: translateY(0); }
}

.leaderboard td {
  padding: 4px 16px;
  /* Scales with window height so all rows fit without scrolling */
  height: clamp(40px, 6.8vh, 64px);
  font-family: var(--font-title);
  font-weight: 600;
  font-size: clamp(16px, 2.4vh, 22px);
  color: #f2f2f0;
  background: linear-gradient(180deg, #171c23, #10141a);
}

.leaderboard td.col-rank {
  padding-left: 20px;
  text-align: left;
}

/* Shields come from a sprite sheet: assets/rank.png holds four 380x360 shields
   at x = 28 / 414 / 798 / 1186, y = 290. --w sets the on-screen width and
   everything else scales from it. */
.rank-badge {
  --w: clamp(40px, 6vh, 60px);
  --x: 1186;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--w);
  height: calc(var(--w) * 360 / 380);
  padding-bottom: calc(var(--w) * 0.05);
  vertical-align: middle;
  font-family: var(--font-title);
  font-weight: 800;
  font-size: calc(var(--w) * 0.38);
  color: #ffffff;
  /* Dark outline so the number reads on the bright gold/silver/bronze faces */
  text-shadow:
    0 0 2px rgba(0, 0, 0, 0.9),
    0 1px 2px rgba(0, 0, 0, 0.9),
    0 0 6px rgba(0, 0, 0, 0.6);
}

.rank-badge::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url('../assets/rank.png') no-repeat;
  background-size: calc(var(--w) * 1599 / 380) auto;
  background-position: calc(var(--w) * var(--x) / -380) calc(var(--w) * 290 / -380);
  /* The sheet has a dark background, not transparency; lighten drops it into the row colour */
  mix-blend-mode: lighten;
}

.rank-badge span { position: relative; }

tr[data-rank="1"] .rank-badge { --x: 28; }
tr[data-rank="2"] .rank-badge { --x: 414; }
tr[data-rank="3"] .rank-badge { --x: 798; }

.leaderboard td.player-name {
  font-weight: 600;
  font-size: clamp(17px, 2.6vh, 24px);
  padding-left: 20px;
  white-space: nowrap;
}

.leaderboard td.points-val {
  font-weight: 800;
  font-size: clamp(19px, 3vh, 27px);
  /* Gold tint layered over the solid row colour so the background can't show through */
  background:
    linear-gradient(90deg, rgba(90, 70, 30, 0.35), rgba(60, 48, 24, 0.25)),
    linear-gradient(180deg, #171c23, #10141a);
}

.leaderboard td.points-val,
.leaderboard thead .col-points {
  color: #f0c863;
}

.hint {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  margin: 4px 0 2px;
}

/* Overlay + detail panel */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.7);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 50;
}

.overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.detail-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  max-width: 440px;
  width: 100%;
  padding: 32px;
  position: relative;
  transform: translateY(16px) scale(0.98);
  opacity: 0;
  transition: transform 0.25s cubic-bezier(.2,.8,.2,1), opacity 0.25s ease;
  box-shadow: 0 30px 60px -20px rgba(0,0,0,0.7);
}

.overlay.open .detail-panel {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

.close-btn:hover {
  color: var(--text);
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.detail-rank {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  background: var(--panel-alt);
  flex-shrink: 0;
}

.detail-name {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  margin: 0;
}

.detail-sub {
  color: var(--text-dim);
  font-size: 13px;
  margin: 2px 0 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.stat-box {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.stat-box .val {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
}

.stat-box .lbl {
  font-size: 11.5px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-top: 2px;
}

.bar-row {
  margin-bottom: 12px;
}

.bar-row .bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 5px;
}

.bar-track {
  height: 8px;
  background: var(--panel-alt);
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--gold-soft));
  width: 0%;
  transition: width 0.6s cubic-bezier(.2,.8,.2,1);
}

/* Tablet widths: the one-line player name needs the room, so tighten cell padding */
@media (max-width: 760px) {
  .leaderboard td, .leaderboard th { padding-left: 8px; padding-right: 8px; }
  .leaderboard thead th { font-size: 13px; letter-spacing: 0.1em; }
  .leaderboard td.col-rank, .leaderboard td.player-name { padding-left: 12px; }
}

/* Below this there isn't room for long nicknames on one line */
@media (max-width: 720px) {
  .leaderboard td.player-name { white-space: normal; }
}

@media (max-width: 560px) {
  .col-num.col-hide, th.col-num:nth-child(3), td:nth-child(3) {
    display: none;
  }
  .leaderboard td, .leaderboard th {
    padding: 4px 6px;
    height: 48px;
    font-size: 15px;
  }
  .leaderboard thead th { font-size: 10px; letter-spacing: 0.1em; height: 44px; }
  .leaderboard td.player-name { font-size: 15px; padding-left: 8px; }
  .leaderboard td.points-val { font-size: 17px; }
  .leaderboard td.col-rank { padding-left: 6px; text-align: center; }
  .leaderboard .col-icon svg { width: 28px; height: 24px; }
  .rank-badge { --w: 42px; }
  .board-wrap { padding: 0 12px; }
  .board-card { padding: 0 4px; }
  .bg-suit { display: none; }
  .title-row { gap: 10px; }
  h1 { white-space: normal; }
  .header-stats { gap: 12px; }
}
