:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #888888);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f1f1f1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
}

.topbar h1 { font-size: 20px; margin: 0; }

.balance {
  font-weight: 700;
  background: var(--secondary-bg);
  border-radius: 999px;
  padding: 6px 14px;
}

main { padding: 0 16px; }

h2 { font-size: 16px; margin: 20px 0 10px; }

.me-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--secondary-bg);
  border-radius: 14px;
  padding: 14px 16px;
  margin-top: 8px;
}

.me-rank { font-weight: 600; }

.redeem-btn, .reward-redeem {
  background: var(--button);
  color: var(--button-text);
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.redeem-btn:disabled, .reward-redeem:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Invite card */
.invite-card {
  background: var(--secondary-bg);
  border-radius: 14px;
  padding: 14px 16px;
  margin-top: 18px;
}

.invite-card h2 { margin: 0 0 4px; }
.invite-tagline { margin: 0 0 12px; font-size: 13px; color: var(--hint); }

.invite-link-row { display: flex; gap: 8px; }

.invite-link {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--hint);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
}

.invite-btn {
  background: var(--button);
  color: var(--button-text);
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.invite-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.invite-share { width: 100%; margin-top: 10px; }

.invite-stats { font-size: 13px; color: var(--hint); margin: 12px 0 0; }

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

.leaderboard li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 10px;
  border-bottom: 1px solid var(--secondary-bg);
}

.leaderboard li.me { background: var(--secondary-bg); border-radius: 10px; }

.rank-num { width: 28px; text-align: center; font-weight: 700; color: var(--hint); }
.rank-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-pts { font-weight: 700; }

.status { color: var(--hint); font-size: 13px; text-align: center; padding: 8px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}

.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--bg);
  width: 100%;
  max-width: 520px;
  border-radius: 16px 16px 0 0;
  padding: 16px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; }

.close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--hint);
  cursor: pointer;
}

.modal-balance { color: var(--hint); }

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

.rewards li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 6px;
  border-bottom: 1px solid var(--secondary-bg);
}

.reward-info { flex: 1; }
.reward-name { font-weight: 600; }
.reward-meta { font-size: 12px; color: var(--hint); }

/* Redemption history */
.redemptions { list-style: none; margin: 0; padding: 0; }

.redemptions li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 6px;
  border-bottom: 1px solid var(--secondary-bg);
}

.rd-info { flex: 1; min-width: 0; }
.rd-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rd-meta { font-size: 12px; color: var(--hint); margin-top: 2px; }

.rd-badge {
  flex-shrink: 0;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
}
.rd-badge.pending { background: #b58900; }
.rd-badge.fulfilled { background: #1f9d55; }
.rd-badge.rejected { background: #d64545; }
