/* Leaderboard layout, rank badges, and rating controls. */

#refreshLeaderboardBtn {
  background-color: #1e3c72;
  color: white;
  border: none;
}

#refreshLeaderboardBtn.leaderboard-refresh-btn {
  min-height: 36px;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 0.82rem;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(30, 60, 114, 0.22);
  white-space: nowrap;
}

#refreshLeaderboardBtn:hover {
  background-color: #0f2b4f;
}

#refreshLeaderboardBtn:disabled {
  background-color: #6c757d;
  cursor: not-allowed;
  opacity: 0.6;
}

.leaderboard-cooldown {
  margin-left: 8px;
  font-size: 0.82rem;
  font-weight: 800;
  color: #667085;
  white-space: nowrap;
}

@media (max-width: 640px) {
  #leaderboard h4 {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
    align-items: center;
  }

  #leaderboard h4 .leaderboard-toggle {
    min-width: 0;
    justify-self: center;
    white-space: nowrap;
  }

  #leaderboard h4 .leaderboard-header-actions {
    grid-column: 2;
    grid-row: 1;
    display: inline-flex !important;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    width: auto;
    margin-left: 0 !important;
  }

  #leaderboard h4::after {
    grid-column: 3;
    grid-row: 1;
  }

  #leaderboard h4 .leaderboard-cooldown {
    display: none;
  }

  #leaderboard h4 .report-btn,
  #leaderboard h4 .leaderboard-help-link,
  #leaderboard h4 .practice-settings-toggle {
    flex: 0 0 auto;
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    padding: 0 !important;
  }

  .leaderboard-settings-controls {
    margin-left: 0;
    position: relative;
  }

  .leaderboard-settings-controls .practice-settings-menu {
    right: 0;
    left: auto;
    top: calc(100% + 8px);
    max-width: min(320px, calc(100vw - 44px));
    border-radius: 22px;
  }

  #refreshLeaderboardBtn.leaderboard-refresh-btn {
    min-width: 0;
    width: 100%;
    padding: 6px 8px !important;
    font-size: 0.74rem !important;
  }
}

/* =========================
   18. LEADERBOARD
   ========================= */

.leaderboard {
  padding: 14px !important;
  border-radius: 22px !important;
  text-align: center;
  position: relative;
  cursor: default;
}

.leaderboard h4 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  margin: 0 0 10px 0 !important;
  font-size: 0.95rem !important;
}

.leaderboard h4:hover {
  opacity: 0.8;
}

.leaderboard h4::after {
  content: "⌄";
  font-size: 1rem;
  transition: transform 0.2s ease;
}

.leaderboard:not(.collapsed) h4::after {
  transform: rotate(180deg);
}

.leaderboard::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: #d0d7e2;
  opacity: 0.8;
}

.leaderboard.collapsed table,
.leaderboard.collapsed #leaderboardTable,
.leaderboard.collapsed .user-rank {
  display: none !important;
}

.leaderboard:not(.collapsed) {
  box-shadow: 0 12px 28px rgba(0,0,0,0.15);
}

.leaderboard-header-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.leaderboard-settings-controls {
  margin-left: auto;
  flex: 0 0 auto;
}

.leaderboard-settings-controls .practice-settings-menu {
  right: 0;
  top: calc(100% + 8px);
}

.leaderboard-settings-controls #rightZoomReset {
  min-width: 64px !important;
}

.leaderboard-help-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(130,148,190,0.22);
  border-radius: 999px;
  background: rgba(255,255,255,0.72);
  color: #4f6bff;
  font-size: 0.84rem;
  font-weight: 900;
  line-height: 1;
  text-decoration: none;
  box-shadow: 0 6px 14px rgba(36,48,84,0.08);
}

.leaderboard-help-link:hover {
  background: rgba(245,247,255,0.96);
  border-color: rgba(79,107,255,0.22);
}

#leaderboardTable {
  width: 100%;
  border-collapse: collapse;
  display: block !important;
  max-height: 260px !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  margin: 0 auto;
}

#leaderboardTable[hidden],
.leaderboard-empty[hidden],
.leaderboard.collapsed .leaderboard-empty {
  display: none !important;
}

#leaderboardTable thead,
#leaderboardTable tbody {
  display: table;
  width: 100%;
  table-layout: fixed;
}

.leaderboard th,
.leaderboard td {
  padding: 7px 8px !important;
  text-align: left;
  border-bottom: 1px solid rgba(130,148,190,0.12) !important;
}

.leaderboard th:first-child,
.leaderboard td:first-child {
  width: 64px;
}

.leaderboard th:last-child,
.leaderboard td:last-child {
  width: 74px;
  text-align: right;
}

.leaderboard th:nth-child(3),
.leaderboard td:nth-child(3) {
  width: 58px;
  text-align: right;
  white-space: nowrap;
}

.leaderboard-empty {
  margin-top: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(246,248,253,0.58);
  border: 1px solid rgba(130,148,190,0.12);
  color: rgba(75,88,124,0.72);
  font-size: 0.92rem;
  font-weight: 700;
  text-align: center;
}

.leaderboard-admin-shadow-row {
  opacity: 0.46;
  filter: saturate(0.75);
}

.leaderboard-admin-shadow-row td {
  padding-top: 10px !important;
  border-top: 1px dashed rgba(130,148,190,0.22) !important;
  background: rgba(248, 250, 252, 0.52);
}

.leaderboard-rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 900;
  line-height: 1;
  color: #fff;
  box-shadow: 0 5px 12px rgba(36, 48, 84, 0.14);
}

.leaderboard-rank-badge--1 {
  background: linear-gradient(135deg, #ffd86b, #d99619);
}

.leaderboard-rank-badge--2 {
  background: linear-gradient(135deg, #dfe7f3, #8c9bb8);
}

.leaderboard-rank-badge--3 {
  background: linear-gradient(135deg, #e8b17e, #a6602b);
}

.leaderboard th {
  background: rgba(79,107,255,0.06) !important;
  font-weight: bold;
}

.leaderboard td:last-child,
.leaderboard th:last-child {
  font-weight: 800;
}

.leaderboard .current-user {
  background: rgba(255, 184, 77, 0.16) !important;
  font-weight: bold;
}

.leaderboard th:first-child,
.leaderboard td:first-child {
  width: 55px;
  text-align: center;
  white-space: nowrap;
}

.leaderboard th:last-child,
.leaderboard td:last-child {
  width: 70px;
  text-align: right;
  white-space: nowrap;
}

.leaderboard th:nth-child(3),
.leaderboard td:nth-child(3) {
  width: 54px;
  text-align: right;
  white-space: nowrap;
}

.leaderboard th:nth-child(2),
.leaderboard td:nth-child(2) {
  word-break: break-word;
  white-space: normal;
}


.leaderboard-hint {
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  background: #1e3c72;
  color: white;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 0.7rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.leaderboard-hint::after {
  content: "";
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #1e3c72;
}

.leaderboard.show-hint .leaderboard-hint {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@keyframes hintPulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(30, 60, 114, 0.35);
  }
  50% {
    transform: scale(1.06);
    box-shadow: 0 0 0 6px rgba(30, 60, 114, 0.15);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(30, 60, 114, 0);
  }
}



.leaderboard.show-hint .leaderboard-toggle {
  display: inline-block;
  animation: hintPulse 1.2s ease-in-out 2;
  border-radius: 10px;
}

.leaderboard.show-hint {
  box-shadow: 0 0 0 2px rgba(30, 60, 114, 0.25);
}

@media (max-width: 800px) {
.leaderboard th:first-child,
.leaderboard td:first-child {
    width: 45px;
  }

  .leaderboard th:last-child,
  .leaderboard td:last-child {
    width: 55px;
  }

  .leaderboard th:nth-child(3),
  .leaderboard td:nth-child(3) {
    width: 46px;
  }
}

.leaderboard {
  margin-top: 8px;
}

.leaderboard-level-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 999px;
  font-size: 0.58rem;
  font-weight: 700;
  line-height: 1.15;
  color: rgba(39, 49, 82, 0.42);
  background: rgba(39, 49, 82, 0.045);
  vertical-align: middle;
  white-space: nowrap;
}

.leaderboard-trophy-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 5px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1.1;
  vertical-align: middle;
  white-space: nowrap;
}

.leaderboard-trophy-badge {
  color: #7a5a11;
  background: rgba(255, 206, 86, 0.13);
  border: 1px solid rgba(180, 126, 22, 0.12);
}

.leaderboard-completed-topics {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  margin-left: 5px;
  font-size: 0.7rem;
  font-weight: 800;
  color: rgba(75, 88, 124, 0.58);
  white-space: nowrap;
}

.leaderboard-weekly-topics {
  font-size: 0.62rem;
  color: rgba(180, 70, 82, 0.48);
}

.leaderboard-weekly-delta {
  color: rgba(180, 70, 82, 0.62);
  font-size: 0.72rem;
  font-weight: 800;
}

.leaderboard-weekly-delta--empty {
  color: rgba(75, 88, 124, 0.26);
  font-weight: 700;
}
