:root {
  --lb-surface: rgba(9, 20, 40, 0.7);
  --lb-surface-strong: rgba(13, 27, 52, 0.84);
  --lb-border: rgba(180, 205, 232, 0.26);
  --lb-border-strong: rgba(180, 205, 232, 0.48);
  --lb-text-main: #e9f2ff;
  --lb-text-muted: #b8c8db;
  --lb-accent: #7ea9d5;
  --lb-top1: rgba(136, 177, 214, 0.24);
  --lb-top2: rgba(121, 163, 204, 0.18);
  --lb-top3: rgba(101, 146, 192, 0.16);
  --lb-success: #7cd6a4;
  --lb-danger: #f0a4a4;
  --lb-stable: #c4d2e0;
}

* {
  box-sizing: border-box;
}

body.lb-page {
  margin: 0;
  color: var(--lb-text-main);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

.lb-app {
  max-width: 1060px;
  margin: 0 auto;
  padding: 18px 14px 32px;
}

.lb-shell {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 50px);
  border: 1px solid var(--lb-border);
  border-radius: 20px;
  background: linear-gradient(165deg, rgba(26, 46, 78, 0.45), rgba(8, 18, 35, 0.72));
  backdrop-filter: blur(8px);
  box-shadow: 0 20px 48px rgba(4, 9, 20, 0.36);
  overflow: hidden;
}

.lb-header {
  padding: 13px 16px 11px;
  border-bottom: 1px solid rgba(180, 205, 232, 0.16);
  background: linear-gradient(180deg, rgba(102, 145, 191, 0.12), rgba(26, 44, 70, 0));
}

.lb-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.lb-title {
  margin: 0;
  font-size: 27px;
  letter-spacing: 0.02em;
}

.lb-subtitle {
  margin: 3px 0 0;
  color: var(--lb-text-muted);
  font-size: 13px;
}

.lb-lang-switch {
  display: flex;
  gap: 6px;
  opacity: 0.88;
}

.lb-mode-switch {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.lb-mode-btn {
  min-height: 38px;
  border-radius: 12px;
  border: 1px solid var(--lb-border);
  background: rgba(13, 31, 58, 0.68);
  color: var(--lb-text-main);
  font-size: 14px;
  line-height: 1.2;
  cursor: pointer;
}

.lb-lang-btn,
.lb-segment-btn {
  min-height: 38px;
  padding: 0 12px;
}

.lb-segment-btn {
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.lb-mode-btn.active {
  border-color: var(--lb-border-strong);
  background: rgba(124, 165, 207, 0.2);
}

.lb-season-card {
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid rgba(180, 205, 232, 0.18);
  background: linear-gradient(145deg, rgba(22, 42, 72, 0.82), rgba(10, 22, 40, 0.86));
  padding: 10px 12px;
}

.lb-season-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.lb-season-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.lb-season-subtitle {
  margin: 0;
  color: var(--lb-text-muted);
  font-size: 13px;
}

.lb-season-separator {
  color: rgba(184, 200, 219, 0.7);
}

.lb-season-meta {
  margin-top: 4px;
  color: var(--lb-text-muted);
  font-size: 12px;
}

.lb-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  min-height: 0;
  flex: 1 1 auto;
}

.lb-top20-title {
  margin: 0;
  padding: 0 6px 4px;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.rank-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.rank-row {
  display: grid;
  grid-template-columns: 42px 24px 32px minmax(0, 1fr) minmax(108px, auto) minmax(88px, auto) minmax(72px, auto);
  align-items: center;
  gap: 6px;
  min-height: 52px;
  margin: 6px 0;
  border-radius: 14px;
  border: 1px solid rgba(181, 207, 233, 0.2);
  background: var(--lb-surface);
  padding: 6px 8px;
}

.rank-row.top-three {
  min-height: 58px;
  border-color: rgba(181, 207, 233, 0.4);
}

.rank-row.hero-row {
  min-height: 64px;
  border-color: rgba(208, 225, 242, 0.56);
  background: linear-gradient(145deg, rgba(175, 214, 244, 0.28), rgba(12, 26, 46, 0.86));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.rank-row[data-rank="1"] {
  background: linear-gradient(140deg, rgba(175, 214, 244, 0.32), rgba(8, 20, 38, 0.82));
}

.rank-row[data-rank="2"] {
  background: linear-gradient(140deg, var(--lb-top2), rgba(8, 20, 38, 0.84));
}

.rank-row[data-rank="3"] {
  background: linear-gradient(140deg, var(--lb-top3), rgba(8, 20, 38, 0.84));
}

.rank-row.current-user {
  border-color: rgba(126, 169, 213, 0.7);
  box-shadow: 0 0 0 1px rgba(126, 169, 213, 0.35);
}

.rank-col {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 17px;
  text-align: center;
}

.hero-row .rank-col {
  font-size: 21px;
}

.top-three .rank-col {
  font-size: 20px;
}

.hero-row .avatar {
  width: 34px;
  height: 34px;
}

.hero-row .name-text {
  font-size: 15px;
  font-weight: 700;
}

.hero-row .points-col {
  font-size: 15px;
  font-weight: 700;
}

.hero-row-tag,
.rank-mini-tag {
  display: inline-flex;
  align-items: center;
  margin-top: 3px;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid rgba(181, 207, 233, 0.18);
  background: rgba(17, 35, 62, 0.42);
  color: var(--lb-text-muted);
  font-size: 11px;
  line-height: 1.2;
}

.rank-mini-tag {
  display: none;
}

.rank-row.top-three .rank-mini-tag {
  display: inline-flex;
}

.flag-col {
  font-size: 16px;
  text-align: center;
}

.avatar-col {
  width: 34px;
  display: flex;
  justify-content: center;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid rgba(181, 207, 233, 0.5);
}

.avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(126, 169, 213, 0.25);
  color: var(--lb-text-main);
  font-size: 13px;
  font-weight: 700;
}

.name-col {
  min-width: 0;
}

.name-text {
  display: block;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.country-text {
  display: block;
  margin-top: 1px;
  color: var(--lb-text-muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.points-col {
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-size: 14px;
}

.delta-col {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  justify-content: flex-end;
  white-space: nowrap;
}

.rank-delta.up {
  color: var(--lb-success);
}

.rank-delta.down {
  color: var(--lb-danger);
}

.rank-delta.stable {
  color: var(--lb-stable);
}

.rank-up,
.rank-down,
.rank-stable {
  transition: none;
}

.badges-col {
  justify-self: end;
}

.lb-leader-gap {
  border: 1px solid rgba(180, 205, 232, 0.22);
  border-radius: 12px;
  background: rgba(12, 23, 44, 0.42);
}

.lb-leader-gap > summary {
  padding: 12px;
  min-height: 44px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}

.lb-leader-gap > summary:focus-visible {
  outline: 2px solid var(--lb-accent);
  outline-offset: -2px;
  border-radius: 12px;
}

.leader-gap-card {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  padding: 4px 12px 12px;
}

.leader-gap-card dt { color: var(--lb-text-muted); font-size: 12px; }
.leader-gap-card dd { margin: 4px 0 0; font-size: 14px; overflow-wrap: anywhere; }
.leader-gap-prompt { margin: 0; padding: 0 12px 12px; color: var(--lb-text-muted); font-size: 13px; }
.lb-ranking-note { padding: 12px 6px; }
.rank-separator { text-align: center; color: var(--lb-text-muted); padding: 6px; border-top: 1px solid var(--lb-border); margin-top: 14px; }
.current-user-tag { display: inline-block; margin-top: 3px; padding: 2px 6px; border-radius: 999px; background: rgba(126, 169, 213, 0.25); font-size: 11px; color: var(--lb-text-main); }
.rank-row.current-user { background-color: rgba(53, 85, 124, 0.42); }

.badge-strip {
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: flex-end;
  position: relative;
}

.badge-slot {
  position: relative;
}

.badge-icon-btn {
  min-width: 28px;
  min-height: 28px;
  border: 1px solid rgba(180, 205, 232, 0.45);
  border-radius: 999px;
  background: rgba(17, 35, 62, 0.82);
  color: var(--lb-text-main);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.badge-icon-btn:focus-visible,
.lb-mode-btn:focus-visible,
.lb-retry-btn:focus-visible {
  outline: 2px solid rgba(126, 169, 213, 0.95);
  outline-offset: 2px;
}

.badge-overflow {
  min-width: 22px;
  min-height: 22px;
  border-radius: 999px;
  border: 1px solid rgba(180, 205, 232, 0.4);
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--lb-text-muted);
}

.badges-empty {
  color: var(--lb-text-muted);
  font-size: 12px;
}

.badge-popover {
  position: absolute;
  right: 0;
  top: 36px;
  z-index: 20;
  width: 210px;
  border-radius: 10px;
  border: 1px solid rgba(180, 205, 232, 0.4);
  background: rgba(12, 23, 44, 0.96);
  padding: 9px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.4);
}

.badge-popover.hidden {
  display: none;
}

.badge-popover-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
}

.badge-popover-desc {
  margin: 5px 0 0;
  color: var(--lb-text-muted);
  font-size: 12px;
  line-height: 1.4;
}

.lb-status {
  margin-bottom: 10px;
  border-radius: 12px;
  border: 1px solid rgba(180, 205, 232, 0.35);
  background: var(--lb-surface-strong);
  padding: 10px;
}

.lb-status.hidden {
  display: none;
}

.lb-status.error {
  border-color: rgba(236, 174, 174, 0.46);
}

.status-text {
  margin: 0;
  color: var(--lb-text-muted);
  font-size: 13px;
}

.lb-retry-btn {
  margin-top: 8px;
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(180, 205, 232, 0.5);
  background: rgba(18, 36, 64, 0.9);
  color: var(--lb-text-main);
  cursor: pointer;
  padding: 0 12px;
}

.lb-retry-btn.hidden {
  display: none;
}

.rank-row.skeleton {
  grid-template-columns: 1fr;
}

.rank-row.skeleton span {
  display: block;
  height: 14px;
  border-radius: 8px;
  background: linear-gradient(90deg, rgba(120, 145, 176, 0.2), rgba(143, 167, 196, 0.36), rgba(120, 145, 176, 0.2));
  background-size: 200% 100%;
  animation: lb-shimmer 1.2s linear infinite;
}

@keyframes lb-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .rank-row.skeleton span {
    animation: none;
  }

  .rank-up,
  .rank-down,
  .rank-stable {
    transition: none;
  }
}

@media (max-width: 900px) {
  .rank-row {
    grid-template-columns: 32px 18px 30px minmax(0, 1fr) auto;
    grid-template-areas:
      "rank flag avatar name badges"
      "rank flag avatar points delta";
    align-items: start;
    row-gap: 4px;
  }

  .rank-col { grid-area: rank; align-self: center; }
  .flag-col { grid-area: flag; align-self: center; }
  .avatar-col { grid-area: avatar; align-self: center; }
  .name-col { grid-area: name; }
  .badges-col { grid-area: badges; justify-self: end; }
  .points-col { grid-area: points; text-align: right; font-size: 13px; }
  .delta-col { grid-area: delta; justify-content: flex-start; }

  .badge-popover {
    right: -4px;
    width: 196px;
  }

  .lb-mode-switch {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .lb-title {
    font-size: 24px;
  }

  .rank-row {
    grid-template-columns: 28px 16px 30px minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "rank flag avatar name name"
      "rank flag avatar points delta"
      "rank flag avatar badges badges";
    padding: 6px;
    margin: 5px 0;
  }

  .delta-col { white-space: normal; font-size: 11px; justify-content: flex-end; text-align: right; }
  .points-col { text-align: left; overflow-wrap: anywhere; }

  .name-text {
    max-width: 100%;
  }

  .lb-app {
    padding-left: 10px;
    padding-right: 10px;
  }

  .lb-main {
    padding: 10px;
  }

  .hero-row {
    min-height: 60px;
  }
}
