/* Экран «Рейтинг» (ui/leaderboard.js), префикс ldb-. Сцена сверху (ui/scene-art.js) держит свои цвета в обеих
   темах; лист и строки — на общих переменных оболочки: --surface --surface-2 --ink --ink-soft --line --good --bad
   --radius-card --nav-h. Плоско: без теней. Геометрия героя — по контракту со сценой: 304 px, колонки 72 px
   с зазором 6 px, высоты 124/96/72, низ колонок на 24 px выше низа героя, лист заходит на последние 24 px. */

.ldb {
  --ldb-hero-h: 304px;
  --ldb-hero-sky: #f6c88d;
  --ldb-hero-ink: #3a2a1e;
  --ldb-hero-ink-soft: rgba(58, 42, 30, 0.62);
  --ldb-col-1: #56624f;
  --ldb-col-2: #a4533f;
  --ldb-col-3: #e08a22;
  --ldb-ribbon: #d97a26;
  --ldb-up: var(--good);
  --ldb-down: #b4553e;
  --ldb-down: color-mix(in srgb, var(--bad) 45%, #9a4430);
  --ldb-me-border: #6e3a26;
  --ldb-me-border: color-mix(in srgb, var(--ink) 70%, #9a4a2c);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

.ldb [hidden] {
  display: none !important;
}

.ldb button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.ldb button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* --- «потянуть, чтобы обновить» ---------------------------------------------------------- */

.ldb-pull {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 0;
  overflow: hidden;
  opacity: 0;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  transition: height 0.2s ease, opacity 0.2s ease;
}

.ldb.is-pulling .ldb-pull {
  height: calc(var(--ldb-pull, 0px) * 0.5);
  opacity: 1;
  transition: none;
}

.ldb.is-pull-ready .ldb-pull .icon {
  transform: rotate(180deg);
}

/* --- герой: сцена, заголовок, пьедестал -------------------------------------------------- */

.ldb-hero {
  position: relative;
  height: var(--ldb-hero-h);
  overflow: hidden;
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  background: linear-gradient(180deg, var(--ldb-hero-sky) 0%, #fbe4c6 100%);
  color: var(--ldb-hero-ink);
}

.ldb-hero.has-scene {
  background: var(--ldb-hero-sky);
}

.ldb-scene {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ldb-scene > svg {
  display: block;
  width: 100%;
  height: 100%;
}

.ldb-title {
  position: absolute;
  top: 26px;
  left: 56px;
  right: 56px;
  margin: 0;
  text-align: center;
  font-size: 20px;
  line-height: 28px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--ldb-hero-ink);
}

.ldb-refresh {
  position: absolute;
  top: 24px;
  right: 16px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  color: var(--ldb-hero-ink) !important;
}

.ldb.is-loading .ldb-refresh .icon {
  animation: ldb-spin 0.9s linear infinite;
}

@keyframes ldb-spin {
  to {
    transform: rotate(360deg);
  }
}

.ldb-podium {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.ldb-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 72px;
}

.ldb-place-avatar {
  position: relative;
  display: grid;
  place-items: center;
  margin-bottom: -2px;
}

.ldb-place.is-me .avatar-face {
  outline: 3px solid #fff;
}

.ldb-ph {
  display: block;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  border: 2px dashed rgba(58, 42, 30, 0.22);
  box-sizing: border-box;
}

.ldb-ph.skel {
  border: 0;
}

.ldb-ribbon {
  position: absolute;
  left: 50%;
  bottom: -9px;
  transform: translateX(-50%);
  padding: 2px 10px;
  background: var(--ldb-ribbon);
  color: #fff;
  font-size: 10px;
  line-height: 14px;
  font-weight: 800;
  white-space: nowrap;
  clip-path: polygon(0 0, 100% 0, calc(100% - 5px) 50%, 100% 100%, 0 100%, 5px 50%);
  z-index: 1;
}

.ldb-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
  width: 72px;
  padding: 8px 4px 0;
  border-radius: 18px 18px 0 0;
  color: #fff;
  overflow: hidden;
}

.ldb-place-1 .ldb-col {
  height: 124px;
  padding-top: 16px;
  background: var(--ldb-col-1);
}

.ldb-place-2 .ldb-col {
  height: 96px;
  background: var(--ldb-col-2);
}

.ldb-place-3 .ldb-col {
  height: 72px;
  background: var(--ldb-col-3);
}

.ldb-num {
  font-size: 28px;
  line-height: 32px;
  font-weight: 800;
}

.ldb-place-1 .ldb-num {
  font-size: 36px;
  line-height: 40px;
}

.ldb-place-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  line-height: 14px;
  font-weight: 700;
}

.ldb .ldb-col .ldb-place-profit {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  max-width: 100%;
  font-size: 10px;
  line-height: 14px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.92);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* --- лист со строками -------------------------------------------------------------------- */

.ldb-sheet {
  position: relative;
  z-index: 1;
  margin-top: -24px;
  padding: 18px 12px 16px 8px;
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  background: var(--surface);
}

.ldb.has-pinned .ldb-sheet {
  padding-bottom: 84px;
}

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

.ldb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
}

.ldb-rank {
  flex: none;
  width: 44px;
  text-align: center;
  font-size: 20px;
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.ldb-rank .skel {
  margin: 0 auto;
}

.ldb-card {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  box-sizing: border-box;
  padding: 10px 14px 10px 12px;
  border: 1.5px solid transparent;
  border-radius: 20px;
  background: var(--surface-2);
}

.ldb-row.is-me .ldb-card {
  border-color: var(--ldb-me-border);
}

.ldb-who {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ldb-who .skel-line {
  width: 60%;
}

.ldb-name {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  line-height: 20px;
  font-weight: 700;
}

.ldb-you {
  flex: none;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--surface);
  font-size: 10px;
  line-height: 14px;
  font-weight: 800;
}

.ldb-profit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  line-height: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.ldb-profit.tone-good,
.ldb-profit.tone-bad,
.ldb-profit {
  color: var(--ink-soft);
}

.ldb-delta {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.ldb-mark {
  display: block;
  flex: none;
}

.ldb-mark-up {
  width: 12px;
  height: 9px;
  background: var(--ldb-up);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.ldb-mark-down {
  width: 12px;
  height: 9px;
  background: var(--ldb-down);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.ldb-mark-same {
  width: 10px;
  height: 3px;
  border-radius: 2px;
  background: var(--ink-soft);
}

.ldb-new {
  padding: 3px 6px;
  border-radius: 6px;
  background: rgba(21, 149, 90, 0.14);
  background: color-mix(in srgb, var(--good) 15%, transparent);
  color: var(--good);
  font-size: 10px;
  line-height: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.ldb-updated {
  padding: 4px 0 0 52px;
  font-size: 12px;
  color: var(--ink-soft);
}

.ldb-updated:empty {
  display: none;
}

/* --- своя строка над нижней панелью ------------------------------------------------------ */

.ldb-pinned {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h, 92px) + 4px);
  transform: translateX(-50%);
  z-index: 6;
  box-sizing: border-box;
  width: min(calc(100% - 32px), 520px);
  padding: 6px 8px 6px 4px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--surface);
}

.ldb-pinned .ldb-row {
  margin: 0;
}

/* --- состояния ------------------------------------------------------------------------- */

.ldb-status:empty {
  display: none;
}

.ldb-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 16px 22px;
  text-align: center;
}

.ldb-state-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--ink-soft);
}

.ldb-state-error .ldb-state-icon {
  color: var(--bad);
}

.ldb-state-title {
  font-size: 16px;
  font-weight: 800;
}

.ldb-state-text {
  max-width: 280px;
  font-size: 13px;
  line-height: 18px;
  color: var(--ink-soft);
}

.ldb-retry {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--surface) !important;
  font-weight: 700;
  font-size: 14px;
}

@media (max-width: 350px) {
  .ldb-rank {
    width: 34px;
    font-size: 17px;
  }

  .ldb-card {
    gap: 10px;
    padding: 8px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ldb.is-loading .ldb-refresh .icon {
    animation: none;
  }
}

/* Экран во всю ширину, как профиль: сцена от края до края, лист — на всю оставшуюся высоту. */
.screen.ldb {
  padding: 0 0 var(--nav-h, 96px);
}

.screen.ldb .ldb-hero {
  border-radius: 0;
}

.screen.ldb .ldb-hero,
.screen.ldb .ldb-sheet {
  width: 100%;
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
}

.screen.ldb .ldb-sheet {
  min-height: calc(100% - var(--ldb-hero-h) + 24px);
  box-sizing: border-box;
}

/* Чуть больше воздуха между концом списка и нижней панелью. */
.screen.ldb .ldb-sheet {
  padding-bottom: 32px;
}
