/* Цвета берутся из темы Telegram; запасные значения — для открытия вне Telegram */
:root {
  --fb-bg: #f2f2f7;
  --fb-card: #ffffff;
  --fb-text: #0b0b0c;
  --fb-hint: #8a8a8e;
  --fb-accent: #2f80ed;
  --fb-accent-text: #ffffff;
  --fb-danger: #e5484d;

  --bg: var(--tg-theme-secondary-bg-color, var(--fb-bg));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-card)));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --accent: var(--tg-theme-button-color, var(--fb-accent));
  --accent-text: var(--tg-theme-button-text-color, var(--fb-accent-text));
  --link: var(--tg-theme-link-color, var(--accent));
  --danger: var(--tg-theme-destructive-text-color, var(--fb-danger));
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--hint) 12%, transparent);
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --good: #2fb35a;
  --gold: #e0a100;

  --radius: 16px;
  --gap: 12px;
  --tabbar-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fb-bg: #0f0f12;
    --fb-card: #1c1c21;
    --fb-text: #f2f2f5;
    --fb-hint: #8d8d96;
    --fb-accent: #4c9bff;
    --fb-danger: #ff6369;
  }
}
:root[data-theme="dark"] {
  --fb-bg: #0f0f12;
  --fb-card: #1c1c21;
  --fb-text: #f2f2f5;
  --fb-hint: #8d8d96;
  --fb-accent: #4c9bff;
  --fb-danger: #ff6369;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { opacity: .45; cursor: default; }
svg { display: block; }

#app {
  padding: 12px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
}

.view { display: flex; flex-direction: column; gap: var(--gap); }

/* ---------- карточки и заголовки ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
}
.card.flush { padding: 0; overflow: hidden; }
.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--hint);
  margin: 8px 4px -4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-title { font-weight: 600; font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 600;
  background: var(--soft);
  color: var(--text);
  transition: transform .08s ease, opacity .15s;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.tinted { background: var(--accent-soft); color: var(--link); }
.btn.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.btn.block { width: 100%; }
.btn.big { min-height: 52px; font-size: 16px; border-radius: 14px; }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--soft);
  font-size: 14px;
  font-weight: 500;
}
.chip.active { background: var(--accent); color: var(--accent-text); }

.segmented {
  display: flex;
  background: var(--soft);
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
}
.segmented button {
  flex: 1;
  min-height: 34px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  color: var(--hint);
}
.segmented button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---------- поля ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--hint); padding-left: 2px; }
.input, textarea.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--sep);
  background: var(--bg);
  outline: none;
  font-size: 16px; /* меньше 16px — iOS зумит страницу */
}
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 88px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 36px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

input[type=range] {
  width: 100%;
  accent-color: var(--accent);
  height: 28px;
}

/* ---------- таб-бар ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--sep);
  z-index: 20;
}
.tab {
  flex: 1;
  max-width: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0;
  border-radius: 12px;
  color: var(--hint);
  font-size: 11px;
  font-weight: 600;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--accent); }

/* ---------- загрузка / занятость ---------- */
.splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.busy { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 60; padding: 16px; }
.busy-box {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px 24px;
  min-width: 220px;
  max-width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  text-align: center;
}
.progress { width: 100%; height: 6px; border-radius: 3px; background: var(--soft); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .2s; }

.toast {
  position: fixed;
  left: 16px; right: 16px;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  margin: 0 auto;
  max-width: 420px;
  background: color-mix(in srgb, var(--text) 88%, transparent);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  text-align: center;
  z-index: 70;
  animation: toast-in .2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- пустые состояния ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 12px;
  padding: 32px 20px;
}
.empty-icon {
  width: 72px; height: 72px; border-radius: 22px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-size: 34px;
}
.empty h2 { margin: 4px 0 0; font-size: 20px; }
.empty p { margin: 0; color: var(--hint); max-width: 320px; }

/* ---------- редактор ---------- */
.track-head { display: flex; gap: 14px; align-items: center; }
.cover {
  position: relative;
  width: 92px; height: 92px;
  border-radius: 14px;
  flex: none;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid; place-items: center;
  overflow: hidden;
}
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover svg { width: 36px; height: 36px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.cover-edit {
  position: absolute; right: 4px; bottom: 4px;
  width: 26px; height: 26px; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff;
  display: grid; place-items: center; font-size: 13px;
}
.track-title { font-weight: 700; font-size: 17px; line-height: 1.25; word-break: break-word; }
.track-artist { color: var(--hint); margin-top: 2px; word-break: break-word; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pill {
  font-size: 12px; font-weight: 600;
  padding: 3px 8px; border-radius: 999px;
  background: var(--soft); color: var(--hint);
}
.pill.accent { background: var(--accent-soft); color: var(--link); }
.pill.gold { background: color-mix(in srgb, var(--gold) 18%, transparent); color: var(--gold); }
.pill.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.pill.good { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }

.player { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.play {
  width: 44px; height: 44px; flex: none; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center;
}
.play svg { width: 20px; height: 20px; fill: currentColor; }
.wave-wrap { position: relative; flex: 1; min-width: 0; }
.wave { width: 100%; height: 56px; touch-action: none; cursor: pointer; }
.times { display: flex; justify-content: space-between; font-size: 12px; color: var(--hint); margin-top: 2px; }

.tool-body { margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.range-label { display: flex; justify-content: space-between; font-size: 14px; }
.range-label b { font-variant-numeric: tabular-nums; }
.big-value { font-size: 28px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }

.actions { display: flex; flex-direction: column; gap: 8px; }

/* ---------- профиль ---------- */
.profile-head { display: flex; align-items: center; gap: 14px; }
.avatar {
  position: relative;
  width: 64px; height: 64px; border-radius: 50%;
  flex: none; overflow: hidden;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text);
  font-size: 24px; font-weight: 700;
}
.avatar.sm { width: 40px; height: 40px; font-size: 16px; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.profile-name { font-size: 20px; font-weight: 700; line-height: 1.2; }

.premium-card { position: relative; overflow: hidden; }
.premium-card.on {
  background: linear-gradient(135deg, color-mix(in srgb, var(--gold) 22%, var(--card)), var(--card) 70%);
}

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats.two { grid-template-columns: repeat(2, 1fr); }
.stat {
  background: var(--card);
  border-radius: 14px;
  padding: 12px;
  min-width: 0;
}
.card .stat { background: var(--bg); }
.stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--hint); margin-top: 2px; }
.stat-sub { font-size: 12px; color: var(--hint); }

.chart { position: relative; }
.bars {
  display: flex; align-items: flex-end; gap: 2px;
  height: 120px;
  border-bottom: 1px solid var(--sep);
}
.bar-hit { flex: 1; height: 100%; display: flex; align-items: flex-end; min-width: 0; }
.bar {
  width: 100%;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 0;
}
.bar-hit:hover .bar, .bar-hit.on .bar { background: color-mix(in srgb, var(--accent) 75%, var(--text)); }
.bar.zero { background: var(--soft); height: 2px !important; border-radius: 1px; }
.chart-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--hint); margin-top: 6px; }
.chart-max { position: absolute; top: -2px; left: 0; font-size: 11px; color: var(--hint); }
.chart-tip {
  position: fixed;
  z-index: 80;
  pointer-events: none;
  background: var(--text);
  color: var(--bg);
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 8px;
  white-space: nowrap;
  transform: translate(-50%, -100%);
}

.achievements { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ach {
  background: var(--bg);
  border-radius: 14px;
  padding: 12px 8px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.ach-icon { font-size: 26px; line-height: 1; }
.ach.locked .ach-icon { filter: grayscale(1); opacity: .45; }
.ach-title { font-size: 12px; font-weight: 600; line-height: 1.2; }
.ach .progress { height: 4px; margin-top: 4px; }

.quote {
  border-left: 3px solid var(--accent);
  padding: 4px 0 4px 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.review { padding: 12px 0; border-bottom: 1px solid var(--sep); }
.review:last-child { border-bottom: 0; }
.review-author { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.review-text { white-space: pre-wrap; word-break: break-word; }

/* ---------- админка ---------- */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--sep);
  text-align: left;
  width: 100%;
}
.list-item:last-child { border-bottom: 0; }
.list-item:active { background: var(--soft); }
.list-item .chev { color: var(--hint); font-size: 18px; }
.log-item { padding: 10px 16px; border-bottom: 1px solid var(--sep); }
.log-item:last-child { border-bottom: 0; }
.log-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--hint); }
.log-user { color: var(--link); font-weight: 600; }
.log-action { margin-top: 2px; word-break: break-word; }
.log-value { color: var(--hint); font-size: 13px; word-break: break-word; }
.top-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--sep); width: 100%; text-align: left; }
.top-row:last-child { border-bottom: 0; }
.top-place { width: 22px; color: var(--hint); font-weight: 700; font-variant-numeric: tabular-nums; }
.date-row { display: flex; gap: 8px; }
.date-row .input { min-width: 0; }

/* ---------- шторка ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-height: 92vh;
  max-width: 640px; margin: 0 auto;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  z-index: 41;
  display: flex; flex-direction: column;
  animation: sheet-in .22s ease;
}
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--sep); margin: 8px auto 4px; flex: none; }
.sheet-body {
  overflow-y: auto;
  padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: var(--gap);
}

@media (max-width: 360px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .achievements { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- редактор: шаги, правки ---------- */
.steps { display: flex; flex-direction: column; gap: 12px; }
.step { display: flex; align-items: center; gap: 12px; }
.step-num {
  width: 28px; height: 28px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--link); font-weight: 700; font-size: 14px;
}
.chip.static { cursor: default; background: var(--accent-soft); color: var(--link); }
input[type=range].dim { opacity: .45; }
.cover.sm { width: 64px; height: 64px; border-radius: 12px; }
.cover.sm svg { width: 26px; height: 26px; }

/* ---------- премиум ---------- */
.perks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.perks li::before { content: '✓'; color: var(--good); font-weight: 700; margin-right: 8px; }

/* ---------- бонусы ---------- */
.hero { text-align: left; }
.hero-icon {
  width: 52px; height: 52px; border-radius: 16px; font-size: 26px;
  display: grid; place-items: center; background: var(--accent-soft);
}
.link-box {
  display: block; width: 100%; text-align: left;
  padding: 12px; border-radius: 12px; background: var(--bg);
  border: 1px dashed var(--sep);
  font: 14px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all; color: var(--link);
}

/* ---------- админка ---------- */
.chips.scroll {
  flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px; padding: 0 16px 2px;
}
.chips.scroll::-webkit-scrollbar { display: none; }
.chips.scroll .chip { flex: none; }
.badge {
  display: inline-grid; place-items: center;
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px;
  border-radius: 9px; font-size: 11px; font-weight: 700;
  background: var(--danger); color: #fff;
}
.progress.big { height: 10px; border-radius: 5px; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: '›'; float: right; color: var(--hint); transition: transform .15s; }
details[open] > summary::after { transform: rotate(90deg); }

/* ---------- рассылка ---------- */
.toolbar { display: flex; gap: 4px; flex-wrap: wrap; }
.toolbar button {
  min-width: 36px; height: 34px; padding: 0 8px; border-radius: 8px;
  background: var(--soft); font-size: 14px;
}
.toolbar button:active { background: var(--accent-soft); }
.input.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }
#bc-count.over { color: var(--danger); font-weight: 600; }
.btn-editor { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 12px; background: var(--bg); }
.chip.color-primary.active { background: #2f80ed; color: #fff; }
.chip.color-success.active { background: #2fb35a; color: #fff; }
.chip.color-danger.active { background: #e5484d; color: #fff; }

.post-preview {
  padding: 16px; border-radius: var(--radius);
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 18%, var(--bg)), var(--bg));
  display: flex; flex-direction: column; gap: 4px;
}
.post-bubble {
  max-width: 92%; background: var(--card); border-radius: 16px 16px 16px 4px;
  overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.12);
}
.post-photo {
  height: 180px; background: var(--soft) center / cover no-repeat;
  display: grid; place-items: center; font-size: 40px;
}
.post-text { padding: 10px 12px; white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.post-text a { color: var(--link); }
.post-text code, .post-text pre { font-family: ui-monospace, Menlo, monospace; background: var(--soft); border-radius: 4px; padding: 0 3px; }
.post-text blockquote { margin: 4px 0; padding: 2px 0 2px 10px; border-left: 3px solid var(--accent); }
.post-text .spoiler { background: var(--hint); color: transparent; border-radius: 4px; }
.post-text .premium-emoji { outline: 1px dashed var(--gold); border-radius: 4px; }
.post-btn-row { display: flex; gap: 4px; max-width: 92%; }
.post-btn {
  flex: 1; text-align: center; padding: 9px 8px; border-radius: 10px;
  background: color-mix(in srgb, var(--card) 70%, transparent); backdrop-filter: blur(6px);
  font-size: 14px; font-weight: 600; color: var(--text);
}
.post-btn.style-primary { background: #2f80ed; color: #fff; }
.post-btn.style-success { background: #2fb35a; color: #fff; }
.post-btn.style-danger { background: #e5484d; color: #fff; }
.confirm-card { border: 2px solid var(--accent); }

/* ---------- спонсоры ---------- */
.switch2 { display: flex; background: var(--soft); border-radius: 12px; padding: 3px; gap: 3px; }
.switch2 button { flex: 1; min-height: 40px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--hint); padding: 4px 6px; }
.switch2 button.active { background: var(--accent); color: var(--accent-text); }
.mini-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.mini-stats > div { background: var(--bg); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; min-width: 0; }
.mini-stats b { font-size: 16px; font-variant-numeric: tabular-nums; }
.mini-stats span { font-size: 11px; color: var(--hint); }
.good-text { color: var(--good); }
.sponsor-logo { background: var(--accent-soft); color: var(--link); }
select.input { appearance: none; }
