:root {
  color-scheme: dark;
  --bg: var(--tg-theme-bg-color, #181a20);
  --text: var(--tg-theme-text-color, #f5f5f5);
  --hint: var(--tg-theme-hint-color, #8a8f9c);
  --btn: var(--tg-theme-button-color, #2ea6ff);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #22252e);
  --accent: #a58aff;
  --danger: #ff5c5c;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px calc(28px + env(safe-area-inset-bottom));
}

.hidden { display: none !important; }

.loader-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 60vh;
}
.spinner {
  width: 38px; height: 38px;
  border: 3px solid var(--card);
  border-top-color: var(--btn);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}

.avatar {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--btn), var(--accent));
  color: var(--btn-text);
  font-size: 30px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 10px;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Вкладки */
.tabs {
  display: flex; gap: 6px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 14px;
}
.tab {
  flex: 1;
  padding: 10px;
  border: none; border-radius: 10px;
  background: transparent; color: var(--hint);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab.active { background: var(--btn); color: var(--btn-text); }

/* Друзья */
.progress {
  height: 8px;
  background: rgba(128,128,128,.18);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--btn), var(--accent));
  border-radius: 999px;
  transition: width .3s;
}
.invite-link {
  background: rgba(128,128,128,.1);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--hint);
  word-break: break-all;
  margin-bottom: 12px;
}

.notice {
  background: rgba(255,193,7,.12);
  border: 1px solid rgba(255,193,7,.3);
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  margin: 12px 0;
}

h1 { font-size: 20px; text-align: center; margin-bottom: 4px; }
.subtitle { color: var(--hint); text-align: center; font-size: 13px; margin-bottom: 18px; }

.field { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid rgba(128,128,128,.12); font-size: 14px; }
.field:last-child { border-bottom: none; }
.field .label { color: var(--hint); }
.field .value { font-weight: 600; text-align: right; }

.balance {
  display: flex; align-items: center; justify-content: space-between;
}
.balance .amount { font-size: 26px; font-weight: 800; color: var(--btn); }

.btn {
  display: block; width: 100%;
  padding: 14px;
  border: none; border-radius: var(--radius);
  background: var(--btn); color: var(--btn-text);
  font-size: 16px; font-weight: 700;
  cursor: pointer;
  transition: opacity .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; border: 1.5px solid var(--btn); color: var(--btn); margin-top: 10px; }
.btn.danger { background: var(--danger); }

.note { color: var(--hint); font-size: 12px; text-align: center; margin-top: 10px; }
.price-tag { text-align: center; font-size: 15px; margin: 12px 0 4px; }
.price-tag b { color: var(--btn); font-size: 20px; }

/* Разбор */
.reading h2 {
  font-size: 17px;
  margin: 26px 0 12px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--btn);
  color: var(--btn);
}
.reading h2:first-child { margin-top: 0; }
.reading p { line-height: 1.65; font-size: 15px; margin-bottom: 12px; }
.reading ul, .reading ol { margin: 0 0 12px 20px; }
.reading li { line-height: 1.6; font-size: 15px; margin-bottom: 6px; }
.reading strong { color: var(--btn); }
.reading blockquote { border-left: 3px solid var(--btn); padding-left: 10px; color: var(--hint); margin-bottom: 12px; }

.status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
}
.status-badge.pending { background: rgba(255,193,7,.15); color: #ffc107; }
.status-badge.failed { background: rgba(255,92,92,.15); color: var(--danger); }
.status-badge.ready { background: rgba(76,175,80,.15); color: #4caf50; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  z-index: 99; box-shadow: 0 4px 16px rgba(0,0,0,.3);
  animation: fadeIn .2s;
}
@keyframes fadeIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
