:root {
  --bg: var(--tg-theme-bg-color, #0f1115);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #1c1f26);
  --card-bg: var(--tg-theme-bg-color, #171a20);
  --text: var(--tg-theme-text-color, #f0f2f5);
  --hint: var(--tg-theme-hint-color, #8b93a1);
  --link: var(--tg-theme-link-color, #5aa9ff);
  --button: var(--tg-theme-button-color, #3dc06c);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --accent: var(--tg-theme-button-color, #3dc06c);
  --nav-active: #3dc06c;
  --radius: 14px;
  --tabbar-h: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  overflow: hidden;                       /* скроллят только разделы, не body */
  background: var(--secondary-bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
}

#app {
  position: relative;
  height: 100vh; height: 100dvh;
  max-width: 600px; margin: 0 auto;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.hidden { display: none !important; }

/* ── Свайпаемые разделы ─────────────────────────────────────────── */
#pages {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: row;
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
#pages::-webkit-scrollbar { display: none; }
#pages { scrollbar-width: none; }

.page {
  flex: 0 0 100%; width: 100%;
  scroll-snap-align: start; scroll-snap-stop: always;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--tabbar-h) + 24px);
}
.page::-webkit-scrollbar { display: none; }
.page { scrollbar-width: none; }

.page-h { font-size: 22px; font-weight: 700; margin: 6px 0 4px; }

/* ── Общие компоненты ───────────────────────────────────────────── */
.card { background: var(--card-bg); border: 1px solid rgba(255,255,255,.05); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card-title { font-weight: 600; font-size: 16px; margin-bottom: 8px; }
.muted { color: var(--hint); font-size: 14px; margin: 4px 0 12px; }
.muted.small-note { font-size: 12px; margin: 12px 0 0; }

.rates { display: flex; gap: 10px; margin: 12px 0 14px; }
.rate-item { flex: 1; background: var(--card-bg); border: 1px solid rgba(255,255,255,.05); border-radius: var(--radius); padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; }
.rate-label { color: var(--hint); font-size: 13px; }
.rate-val { font-weight: 600; }

input { flex: 1; width: 100%; padding: 13px 14px; font-size: 16px; border: none; border-radius: 12px; background: var(--secondary-bg); color: var(--text); outline: none; }
.btn { border: none; border-radius: 12px; padding: 13px 18px; font-size: 16px; font-weight: 600; background: var(--button); color: var(--button-text); cursor: pointer; white-space: nowrap; transition: opacity .15s ease; }
.btn:active { opacity: .7; }
.btn.small { padding: 12px 14px; font-size: 14px; }
.calc-row, .ref-row { display: flex; gap: 8px; }
.ref-row input { font-size: 13px; }

.quote { margin-top: 14px; border-top: 1px solid var(--secondary-bg); padding-top: 12px; }
.quote-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 15px; }
.quote-row span { color: var(--hint); }
.quote-row.big { font-size: 18px; margin-top: 4px; }
.quote-row.big b { color: var(--accent); }

.steps { margin: 6px 0 0; padding-left: 20px; line-height: 1.6; }
.steps li { margin-bottom: 4px; }

/* Профиль */
.profile { display: flex; align-items: center; gap: 14px; }
.avatar { width: 64px; height: 64px; border-radius: 50%; flex-shrink: 0; background: var(--button); background-size: cover; background-position: center; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 26px; }
.profile-info { min-width: 0; }
.p-name { font-weight: 700; font-size: 18px; }
.p-username { color: var(--accent); font-size: 14px; }
.p-id { color: var(--hint); font-size: 12px; margin-top: 2px; }

/* Подарки */
.gift { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--secondary-bg); }
.gift:first-child { border-top: none; }
.gift-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.gift-name { font-weight: 600; }
.gift-sub { color: var(--hint); font-size: 12px; }
.gift-right { display: flex; align-items: center; gap: 10px; }
.gift-gets { color: var(--accent); white-space: nowrap; }
.gift.cheap { opacity: .5; }
.gift-badge { font-size: 12px; color: var(--hint); background: var(--secondary-bg); padding: 3px 8px; border-radius: 8px; white-space: nowrap; }

/* Магазин */
.shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.shop-item { background: var(--card-bg); border: 1px solid rgba(255,255,255,.05); border-radius: var(--radius); padding: 16px 12px; text-align: center; position: relative; }
.shop-emoji { font-size: 34px; }
.shop-name { font-weight: 600; margin-top: 6px; font-size: 14px; }
.shop-price { color: var(--accent); font-size: 13px; margin-top: 2px; }
.shop-soon { position: absolute; top: 8px; right: 8px; font-size: 10px; color: var(--hint); background: var(--secondary-bg); padding: 2px 6px; border-radius: 6px; }
.soon-card { text-align: center; }

/* Статистика (рефералы/профиль) */
.stat-row { display: flex; gap: 10px; margin-bottom: 14px; }
.stat-box { flex: 1; background: var(--card-bg); border: 1px solid rgba(255,255,255,.05); border-radius: var(--radius); padding: 14px; text-align: center; }
.stat-num { font-size: 22px; font-weight: 700; color: var(--accent); }
.stat-cap { color: var(--hint); font-size: 12px; margin-top: 2px; }

/* ── Нижняя навигация ───────────────────────────────────────────── */
#tabbar {
  flex: 0 0 auto;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex; align-items: stretch;
  background: var(--bg);
  border-top: 1px solid rgba(255,255,255,.06);
}
.tab {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--hint); padding: 6px 0; transition: color .2s ease;
}
.tab-icon { display: inline-flex; align-items: center; justify-content: center; padding: 3px 18px; border-radius: 16px; transition: background .2s ease; }
.tab-icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab-label { font-size: 11px; font-weight: 500; }
.tab.active { color: var(--nav-active); }
.tab.active .tab-icon { background: rgba(61,192,108,.16); }
.tab:active .tab-icon { background: rgba(61,192,108,.10); }

/* Toast */
.toast { position: fixed; bottom: calc(var(--tabbar-h) + 20px); left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.88); color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 14px; z-index: 30; max-width: 90%; text-align: center; }
