:root {
  color-scheme: light dark;
  --page: var(--tg-theme-bg-color, #f3f4f7);
  --card: var(--tg-theme-secondary-bg-color, #fff);
  --text: var(--tg-theme-text-color, #171923);
  --muted: var(--tg-theme-hint-color, #7c8493);
  --accent: #ff6a3d;
  --accent-dark: #dc4d26;
  --line: color-mix(in srgb, var(--text) 9%, transparent);
  --soft: color-mix(in srgb, var(--accent) 10%, var(--card));
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; }

.shell {
  width: min(100%, 620px);
  margin: 0 auto;
  padding: calc(18px + var(--tg-safe-area-inset-top, 0px)) 16px calc(26px + var(--tg-safe-area-inset-bottom, 0px));
}

.header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 2px 2px 18px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 16px;
  background: var(--soft);
  font-size: 26px;
}

.brand-copy { min-width: 0; flex: 1; }
.eyebrow, .section-kicker, .hero-label {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .11em;
}

h1 { margin: 1px 0 0; font-size: 20px; line-height: 1.15; letter-spacing: -.025em; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.rank-badge {
  min-width: 58px;
  padding: 7px 10px 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  text-align: center;
}

.rank-badge span { display: block; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .08em; }
.rank-badge strong { display: block; margin-top: 1px; font-size: 19px; line-height: 1.05; }

.hero {
  position: relative;
  display: flex;
  min-height: 146px;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
  padding: 21px 22px;
  border-radius: 24px;
  background: linear-gradient(118deg, #20233b 0%, #38234b 56%, #793149 100%);
  color: #fff;
  box-shadow: 0 12px 30px rgba(47, 30, 62, .2);
}

.hero-copy { position: relative; z-index: 1; }
.hero-label { color: rgba(255,255,255,.66); }
.streak-line { display: flex; align-items: baseline; gap: 8px; margin-top: 4px; }
.streak-line strong { font-size: 52px; line-height: .98; letter-spacing: -.055em; }
.streak-line span { color: rgba(255,255,255,.86); font-size: 14px; }
.hero-hint { margin: 9px 0 0; color: rgba(255,255,255,.78); font-size: 12px; }
.flame { position: relative; z-index: 1; margin-right: 3px; font-size: 67px; filter: drop-shadow(0 7px 14px rgba(255,106,61,.35)); }
.hero-glow { position: absolute; top: -52px; right: -30px; width: 190px; height: 190px; border-radius: 50%; background: rgba(255,121,76,.18); filter: blur(4px); }

.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; margin-top: 12px; }
.stat-card, .today-card, .leaderboard-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  box-shadow: 0 4px 14px rgba(21, 28, 44, .035);
}

.stat-card { position: relative; min-height: 126px; padding: 15px 16px 13px; }
.stat-wide { grid-column: span 2; min-height: 104px; padding-right: 58px; }
.stat-icon { position: absolute; top: 14px; right: 15px; font-size: 18px; }
.stat-label { display: block; padding-right: 24px; color: var(--muted); font-size: 12px; }
.stat-value { display: block; margin-top: 8px; font-size: 29px; line-height: 1; letter-spacing: -.035em; }
.stat-unit { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }

.today-card, .leaderboard-card { margin-top: 12px; padding: 17px; }
.today-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h2 { margin: 2px 0 0; font-size: 17px; line-height: 1.2; letter-spacing: -.02em; }
.today-count { color: var(--accent-dark); font-size: 18px; font-weight: 800; white-space: nowrap; }
.progress-track { height: 9px; margin-top: 14px; overflow: hidden; border-radius: 20px; background: color-mix(in srgb, var(--accent) 13%, var(--page)); }
.progress-fill { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #ff9e43, var(--accent)); transition: width .35s ease; }
.pending { margin: 9px 0 0; color: var(--muted); font-size: 12px; }

.leaderboard-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.participant-count { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.icon-button, .page-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
.icon-button { color: var(--accent-dark); font-size: 24px; }
.icon-button:disabled, .page-button:disabled { opacity: .38; cursor: default; }

.rows { display: grid; gap: 7px; }
.row {
  display: grid;
  grid-template-columns: 38px minmax(0,1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 16px;
  background: color-mix(in srgb, var(--text) 4%, var(--card));
}
.row.self { border-color: color-mix(in srgb, var(--accent) 42%, transparent); background: var(--soft); }
.medal { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 12px; background: var(--card); font-size: 15px; font-weight: 800; }
.row-name { overflow: hidden; font-size: 13px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { margin-top: 2px; color: var(--muted); font-size: 11px; }
.row-reps { color: var(--muted); font-size: 11px; font-weight: 700; white-space: nowrap; }
.empty { padding: 22px 12px; color: var(--muted); text-align: center; font-size: 13px; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 12px; color: var(--muted); font-size: 12px; }
.page-button { width: 34px; height: 34px; border-radius: 12px; font-size: 18px; }
.status { min-height: 18px; margin: 10px 3px 0; color: var(--muted); text-align: center; font-size: 11px; }
.status.error { color: var(--tg-theme-destructive-text-color, #d74444); }
footer { padding: 4px 8px 0; color: var(--muted); text-align: center; font-size: 11px; }

@media (min-width: 540px) {
  .shell { padding-right: 22px; padding-left: 22px; }
  .hero { min-height: 168px; padding: 24px 28px; }
  .streak-line strong { font-size: 60px; }
  .flame { font-size: 76px; }
  .stats-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .stat-wide { grid-column: auto; padding-right: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
