:root {
  --bg: var(--tg-theme-bg-color, #fff);
  --text: var(--tg-theme-text-color, #111);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --sec: var(--tg-theme-secondary-bg-color, #f3f3f5);
  --card: var(--tg-theme-bg-color, #fff);
  --accent: var(--tg-theme-button-color, #2ea6ff);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: 14px 12px calc(34px + env(safe-area-inset-bottom));
}
.hdr { margin-bottom: 12px; }
h1 {
  font-size: 20px; font-weight: 700; margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sub { color: var(--hint); font-size: 13px; margin-top: 2px; }

/* segmented tabs */
.tabs {
  display: flex; gap: 4px; padding: 4px; margin-bottom: 12px;
  background: var(--sec); border-radius: var(--radius);
}
.tab {
  flex: 1; padding: 9px 6px; border: none; border-radius: 10px;
  background: transparent; color: var(--text); font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: background .18s, color .18s; white-space: nowrap;
}
.tab.active { background: var(--card); color: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

/* search */
.searchwrap { position: relative; margin-bottom: 12px; }
.search-ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); opacity: .55; font-size: 14px; }
.search {
  width: 100%; padding: 11px 12px 11px 36px; border: none; border-radius: var(--radius);
  background: var(--sec); color: var(--text); font-size: 15px; outline: none;
}

/* podium */
.podium { display: flex; align-items: flex-end; gap: 8px; margin-bottom: 14px; }
.podium:empty { display: none; }
.pcard {
  flex: 1; background: var(--sec); border-radius: var(--radius); padding: 12px 6px 10px;
  text-align: center; position: relative; min-width: 0;
}
.pcard.gold { background: linear-gradient(160deg, #ffe79a, #ffcf3f); color: #4a3a00; }
.pcard.silver { background: linear-gradient(160deg, #eef1f5, #cfd6df); color: #2c333d; }
.pcard.bronze { background: linear-gradient(160deg, #f6cfa6, #e0a36b); color: #4a2e10; }
.pcard.first { transform: translateY(-8px); }
.pmedal { font-size: 26px; line-height: 1; }
.pav {
  width: 40px; height: 40px; border-radius: 50%; margin: 6px auto 4px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; color: #fff;
}
.pname { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ppts { font-size: 14px; font-weight: 800; margin-top: 2px; }
.pcard.me { outline: 2px solid var(--accent); outline-offset: 1px; }

/* list rows */
.list { display: flex; flex-direction: column; gap: 6px; }
.row {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px;
  background: var(--sec); border-radius: var(--radius);
}
.row.me { background: color-mix(in srgb, var(--accent) 16%, var(--sec)); outline: 1px solid var(--accent); }
.rank { width: 26px; text-align: center; font-weight: 700; color: var(--hint); font-size: 14px; }
.av {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: #fff;
}
.name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.badge {
  font-size: 10px; font-weight: 700; color: var(--accent-text); background: var(--accent);
  border-radius: 6px; padding: 1px 5px; margin-left: 6px;
}
.pts { font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.unit { font-size: 11px; color: var(--hint); font-weight: 600; margin-left: 2px; }

.row.clickable { cursor: pointer; transition: transform .08s; }
.row.clickable:active { transform: scale(0.985); }

.state { text-align: center; color: var(--hint); padding: 44px 16px; line-height: 1.6; }
.state:empty { display: none; }

/* history */
.hrow {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  background: var(--sec); border-radius: var(--radius); font-size: 14px;
}
.hrow .hp { font-weight: 800; min-width: 42px; }
.hp.plus { color: #2bb673; } .hp.minus { color: #e8554e; }
.hrow .hu { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hrow .ht { color: var(--hint); font-size: 12px; }

/* bottom-sheet modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; z-index: 50;
}
.modal.hidden { display: none; }
.sheet {
  width: 100%; background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(26px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,.25); animation: up .22s ease;
}
@keyframes up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.grabber { width: 40px; height: 4px; border-radius: 3px; background: var(--hint); opacity: .4; margin: 4px auto 14px; }

.pf-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.pf-av {
  width: 60px; height: 60px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 24px; color: #fff;
}
.pf-name { font-size: 19px; font-weight: 700; }
.pf-sub { color: var(--hint); font-size: 13px; margin-top: 2px; }

.pf-stats { display: flex; gap: 8px; margin-bottom: 16px; }
.pf-stat { flex: 1; background: var(--sec); border-radius: 12px; padding: 12px 8px; text-align: center; }
.pf-stat .v { font-size: 20px; font-weight: 800; color: var(--accent); }
.pf-stat .k { font-size: 11px; color: var(--hint); margin-top: 3px; }

.pf-chart-title { font-size: 12px; color: var(--hint); margin: 4px 0 8px; }
.pf-chart { width: 100%; height: 90px; display: block; }
