/* ============================================================
   LustMind — Design System
   Тёмная «премиальная» тема: глубокий фиолетовый фон, неоновые
   акценты, стеклянные поверхности, аккуратная типографика.
   ============================================================ */

:root {
  /* Палитра */
  --bg: #08060f;
  --bg-2: #0d0918;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-2: rgba(255, 255, 255, 0.07);
  --surface-3: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(167, 139, 250, 0.32);

  --primary: #8b5cf6;
  --primary-2: #a78bfa;
  --accent: #d946ef;
  --accent-2: #e879f9;
  --grad: linear-gradient(135deg, #8b5cf6, #d946ef);
  --grad-soft: linear-gradient(135deg, rgba(139, 92, 246, 0.22), rgba(217, 70, 239, 0.18));

  --text: #f4f1fb;
  --text-2: #b9aed8;
  --muted: #7d72a0;

  --danger: #fb7185;
  --ok: #34d399;
  --gold: #fbbf24;

  --glow: 0 8px 28px rgba(139, 92, 246, 0.35);
  --glow-sm: 0 4px 16px rgba(139, 92, 246, 0.28);
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.5);

  --radius: 20px;
  --radius-sm: 13px;
  --tabbar-h: 64px;
  --app-h: 100dvh;
  --app-w: 520px;
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

/* Живой фон: два медленно дышащих неоновых пятна */
body::before {
  content: '';
  position: fixed;
  inset: -20%;
  z-index: -1;
  background:
    radial-gradient(42% 34% at 78% 8%, rgba(139, 92, 246, 0.2), transparent 70%),
    radial-gradient(36% 30% at 12% 92%, rgba(217, 70, 239, 0.14), transparent 70%);
  animation: ambient 14s ease-in-out infinite alternate;
}
@keyframes ambient {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(0, -2.5%, 0) scale(1.06); }
}

.hidden { display: none !important; }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.dim { color: var(--text-2); font-size: 13px; line-height: 1.55; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: rgba(167, 139, 250, 0.25); border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Каркас ---------- */
#app {
  display: flex;
  flex-direction: column;
  height: var(--app-h);
  max-width: var(--app-w);
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ============================================================
   Иконки
   ============================================================ */
[data-icon] { display: inline-flex; align-items: center; justify-content: center; }
[data-icon] svg, .ico svg {
  width: 22px; height: 22px;
  display: block;
}
.ico-sm svg { width: 17px; height: 17px; }
.ico-xs svg { width: 14px; height: 14px; }

/* ============================================================
   Drawer (панель диалогов)
   ============================================================ */
.drawer {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 84%;
  max-width: 330px;
  background: rgba(13, 9, 24, 0.92);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border-right: 1px solid var(--border);
  transform: translateX(-104%);
  transition: transform 0.32s cubic-bezier(0.22, 0.9, 0.3, 1);
  z-index: 40;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.drawer.open { transform: translateX(0); }

.drawer-overlay {
  position: absolute; inset: 0;
  background: rgba(4, 2, 10, 0.6);
  backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none;
  transition: opacity 0.28s;
  z-index: 39;
}
.drawer-overlay.show { opacity: 1; pointer-events: auto; }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 18px) 16px 14px;
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 14px; flex: 0 0 auto;
  display: grid; place-items: center; color: #fff;
  background: var(--grad);
  box-shadow: var(--glow);
}
.brand-logo svg { width: 22px; height: 22px; }
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: 0.2px; }
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }

.drawer-search { padding: 0 14px 12px; flex: 0 0 auto; position: relative; }
.drawer-search .search-ico {
  position: absolute; left: 27px; top: 50%; transform: translateY(calc(-50% - 6px));
  color: var(--muted); pointer-events: none;
}
.drawer-search .search-ico svg { width: 16px; height: 16px; }
.drawer-search input {
  width: 100%; padding: 11px 14px 11px 40px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); border-radius: 14px; font-size: 14px; outline: none;
  font-family: inherit;
  transition: border-color 0.2s, background 0.2s;
}
.drawer-search input::placeholder { color: var(--muted); }
.drawer-search input:focus { border-color: var(--border-strong); background: var(--surface-2); }

.chat-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 2px 10px 12px; -webkit-overflow-scrolling: touch; }
.chat-item {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 12px; border-radius: 16px; cursor: pointer;
  border: 1px solid transparent; margin-bottom: 3px;
  transition: background 0.15s, border-color 0.15s;
}
.chat-item:active { background: var(--surface-2); }
.chat-item.active { background: var(--grad-soft); border-color: var(--border-strong); }
.ci-ico {
  width: 36px; height: 36px; border-radius: 12px; flex: 0 0 auto;
  display: grid; place-items: center; color: var(--primary-2);
  background: var(--surface-2);
}
.chat-item.active .ci-ico { color: #fff; background: var(--grad); box-shadow: var(--glow-sm); }
.ci-ico.evil { color: var(--accent-2); }
.ci-body { min-width: 0; flex: 1 1 auto; }
.ci-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.ci-del {
  flex: 0 0 auto; opacity: 0.45; color: var(--muted);
  padding: 6px; border-radius: 9px; background: none; border: none;
  transition: opacity 0.15s, color 0.15s;
}
.ci-del svg { width: 16px; height: 16px; }
.ci-del:active { opacity: 1; color: var(--danger); }
.chat-empty { color: var(--muted); font-size: 13px; padding: 24px 16px; text-align: center; }

.drawer-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  border-top: 1px solid var(--border);
  flex: 0 0 auto;
}
.streak-pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 700; color: var(--text);
  background: linear-gradient(135deg, rgba(251, 146, 60, 0.16), rgba(217, 70, 239, 0.16));
  border: 1px solid rgba(251, 146, 60, 0.28);
  padding: 8px 14px; border-radius: 999px;
}
.streak-pill svg { width: 15px; height: 15px; color: #fb923c; }

/* ============================================================
   Основная колонка
   ============================================================ */
.main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--tabbar-h);
}

.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(8, 6, 15, 0.55);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.topbar-title { flex: 1 1 auto; min-width: 0; }
.t-title {
  font-weight: 800; font-size: 15.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.t-sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.t-sub.evil { color: var(--accent-2); }

.icon-btn {
  flex: 0 0 auto;
  width: 40px; height: 40px; border-radius: 13px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-2); cursor: pointer;
  display: grid; place-items: center;
  transition: transform 0.12s, background 0.2s, color 0.2s, border-color 0.2s;
}
.icon-btn:active { transform: scale(0.9); }
.icon-btn.active {
  background: var(--grad); border-color: transparent; color: #fff;
  box-shadow: var(--glow-sm);
}
.icon-btn.accent { background: var(--grad); border: none; color: #fff; box-shadow: var(--glow-sm); }
.icon-btn.ghost { background: transparent; }

/* ============================================================
   Экраны
   ============================================================ */
.screen {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  animation: screen-in 0.26s ease;
}
/* Дети скроллящегося экрана не должны сжиматься flex'ом (иначе карточки
   с overflow:hidden схлопываются до min-height:0) */
.screen > * { flex: 0 0 auto; }
@keyframes screen-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Чат ---------- */
.chat-screen { padding: 0; overflow: hidden; }

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.messages > * { flex: 0 0 auto; }

.empty-state {
  margin: auto; text-align: center; color: var(--text-2); padding: 24px 12px;
}
.es-logo {
  width: 78px; height: 78px; margin: 0 auto 18px; border-radius: 26px;
  display: grid; place-items: center; color: #fff;
  background: var(--grad);
  box-shadow: 0 16px 48px rgba(139, 92, 246, 0.45);
  animation: breathe 3.2s ease-in-out infinite;
}
.es-logo svg { width: 38px; height: 38px; }
@keyframes breathe {
  0%, 100% { box-shadow: 0 16px 48px rgba(139, 92, 246, 0.45); transform: scale(1); }
  50%      { box-shadow: 0 16px 62px rgba(217, 70, 239, 0.55); transform: scale(1.04); }
}
.empty-state h2 { margin: 0 0 8px; font-size: 22px; color: var(--text); letter-spacing: 0.2px; }
.empty-state p { margin: 0 auto; font-size: 14px; line-height: 1.55; max-width: 300px; }
.es-suggest { display: flex; flex-direction: column; gap: 9px; margin-top: 22px; }
.es-suggest button {
  display: flex; align-items: center; gap: 10px;
  text-align: left; padding: 13px 15px; border-radius: 16px; font-size: 13.5px;
  font-weight: 600; font-family: inherit;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-2);
  cursor: pointer; transition: border-color 0.2s, transform 0.12s, background 0.2s, color 0.2s;
}
.es-suggest button svg { width: 17px; height: 17px; color: var(--primary-2); flex: 0 0 auto; }
.es-suggest button .ico:last-child { margin-left: auto; opacity: 0.4; }
.es-suggest button:active { transform: scale(0.98); border-color: var(--border-strong); color: var(--text); }

/* ---------- Сообщения ---------- */
.msg { display: flex; gap: 9px; max-width: 87%; animation: rise 0.28s cubic-bezier(0.2, 0.8, 0.3, 1); }
@keyframes rise {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.msg.user { align-self: flex-end; flex-direction: row-reverse; }

.msg .avatar {
  width: 29px; height: 29px; border-radius: 10px; flex: 0 0 auto;
  display: grid; place-items: center; margin-top: 2px;
}
.msg .avatar svg { width: 15px; height: 15px; }
.msg.assistant .avatar { background: var(--grad); color: #fff; box-shadow: var(--glow-sm); }
.msg.user .avatar { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); }

.msg .mc { min-width: 0; max-width: 100%; display: flex; flex-direction: column; }
.msg.user .mc { align-items: flex-end; }

.bubble {
  padding: 11px 14px;
  border-radius: 19px;
  font-size: 14.5px; line-height: 1.55;
  word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap;
}
.msg.assistant .bubble {
  background: rgba(23, 16, 42, 0.82);
  border: 1px solid var(--border);
  border-bottom-left-radius: 7px;
}
.msg.user .bubble {
  background: var(--grad);
  color: #fff;
  border-bottom-right-radius: 7px;
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.3);
}

.bubble code {
  background: rgba(139, 92, 246, 0.16); color: #d8c8ff;
  padding: 1.5px 6px; border-radius: 6px;
  font-size: 12.5px; font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}
.bubble pre {
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border);
  padding: 12px; border-radius: 13px;
  overflow-x: auto; margin: 8px 0;
  font-size: 12.5px; line-height: 1.5;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}
.bubble pre code { background: none; padding: 0; color: #e4dcff; }
.bubble strong { font-weight: 700; }
.bubble .md-li {
  display: block; padding-left: 15px; position: relative; margin: 1px 0;
}
.bubble .md-li::before {
  content: ''; position: absolute; left: 2px; top: 0.62em;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent-2); opacity: 0.8;
}
.msg.user .bubble .md-li::before { background: #fff; }

.msg-meta {
  font-size: 10.5px; color: var(--muted);
  margin-top: 5px; padding: 0 4px;
}
.msg.user .msg-meta { text-align: right; }

.msg-actions { display: flex; gap: 2px; margin-top: 4px; }
.msg-actions button {
  display: inline-flex; align-items: center; gap: 5px;
  background: none; border: none; color: var(--muted);
  font-size: 11.5px; font-weight: 600; font-family: inherit;
  cursor: pointer; padding: 5px 8px; border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}
.msg-actions button svg { width: 13px; height: 13px; }
.msg-actions button:active { color: var(--text); background: var(--surface-2); }

/* Индикатор набора текста */
.dots { display: inline-flex; gap: 4px; padding: 4px 2px; }
.dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent-2);
  animation: dot-bounce 1.2s infinite;
}
.dots span:nth-child(2) { animation-delay: 0.15s; }
.dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-5px); opacity: 1; }
}
.cursor {
  display: inline-block; width: 8px; height: 15px;
  background: var(--accent-2); border-radius: 2px;
  vertical-align: text-bottom; margin-left: 2px;
  animation: blink 0.9s infinite;
}
.gen-note {
  font-size: 12px; color: var(--muted); margin-top: 6px;
  display: flex; align-items: center; gap: 5px;
}
.gen-note svg { width: 12px; height: 12px; }

/* ---------- Composer ---------- */
.composer {
  flex: 0 0 auto;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
  border-top: 1px solid var(--border);
  background: rgba(8, 6, 15, 0.55);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.composer-pill {
  position: relative;
  display: flex; align-items: flex-end;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 26px;
  transition: border-color 0.2s;
}
.composer-pill:focus-within { border-color: var(--border-strong); }
.composer textarea {
  width: 100%; resize: none;
  min-height: 48px; max-height: 132px;
  background: transparent; border: none;
  color: var(--text);
  border-radius: 26px; padding: 14px 56px 14px 18px;
  font-size: 15px; font-family: inherit; outline: none; line-height: 1.4;
}
.composer textarea::placeholder { color: var(--muted); }

.composer-round {
  position: absolute; right: 5px; bottom: 5px;
  width: 38px; height: 38px; border-radius: 50%;
  border: none; cursor: pointer;
  display: grid; place-items: center;
  background: transparent; color: var(--muted);
  transition: transform 0.15s, background 0.2s, color 0.2s, opacity 0.2s;
}
.composer-round svg { width: 19px; height: 19px; }
.composer-round:active { transform: scale(0.88); }
.composer-round.send {
  background: var(--grad); color: #fff;
  box-shadow: var(--glow-sm);
  opacity: 0; transform: scale(0.6); pointer-events: none;
}
.composer-round.stop { background: var(--danger); box-shadow: 0 4px 16px rgba(251, 113, 133, 0.4); }
.composer-pill.has-text .composer-round.send {
  opacity: 1; transform: scale(1); pointer-events: auto;
}
.composer-pill.has-text .composer-round:not(.send) { opacity: 0; transform: scale(0.6); pointer-events: none; }

.voice-tip {
  flex: 0 0 auto; text-align: center;
  font-size: 12px; color: var(--text-2);
  padding-top: 8px;
  animation: rise 0.25s ease;
}
.voice-tip.rec { color: var(--danger); font-weight: 600; }

/* Запись голоса: кнопка mic внутри pill */
.composer-round.recording {
  background: var(--danger); color: #fff;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251, 113, 133, 0.55); }
  50%      { box-shadow: 0 0 0 9px rgba(251, 113, 133, 0); }
}

/* ---------- Нет попыток ---------- */
.no-attempts {
  flex: 0 0 auto;
  margin: 12px 14px calc(env(safe-area-inset-bottom) + 12px);
  padding: 18px 16px;
  border-radius: var(--radius);
  background: rgba(251, 113, 133, 0.07);
  border: 1px solid rgba(251, 113, 133, 0.22);
  text-align: center;
  animation: rise 0.3s ease;
}
.no-attempts .na-ico {
  width: 44px; height: 44px; margin: 0 auto 10px; border-radius: 14px;
  display: grid; place-items: center;
  background: rgba(251, 113, 133, 0.14); color: var(--danger);
}
.no-attempts .na-title { font-weight: 800; font-size: 15px; margin-bottom: 4px; }
.no-attempts .na-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }

/* ============================================================
   Tabbar
   ============================================================ */
.tabbar {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: var(--tabbar-h);
  display: flex;
  background: rgba(9, 6, 17, 0.9);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}
.tab {
  position: relative;
  flex: 1 1 0; min-width: 0;
  background: none; border: none; color: var(--muted);
  cursor: pointer;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  transition: color 0.2s;
  padding: 0 2px;
  font-family: inherit;
}
.tab .ti {
  padding: 4px 14px; border-radius: 999px;
  transition: background 0.25s;
}
.tab .ti svg { width: 21px; height: 21px; }
.tab span { font-size: 10px; font-weight: 700; letter-spacing: 0.2px; }
.tab:active .ti { transform: scale(0.92); }
.tab.active { color: var(--accent-2); }
.tab.active .ti { background: rgba(139, 92, 246, 0.18); }

/* ============================================================
   Карточки и компоненты
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-bottom: 12px;
}
.card h3 {
  margin: 0 0 12px;
  font-size: 12px; color: var(--muted);
  font-weight: 800; letter-spacing: 0.9px;
  text-transform: uppercase;
  display: flex; align-items: center; gap: 8px;
}
.card h3 svg { width: 15px; height: 15px; color: var(--primary-2); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat-grid.two { grid-template-columns: repeat(2, 1fr); }
.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 13px 8px 11px;
  text-align: center;
}
.stat svg { width: 16px; height: 16px; color: var(--primary-2); margin: 0 auto 6px; display: block; }
.stat .v {
  font-size: 18px; font-weight: 800;
  background: linear-gradient(135deg, #e879f9, #a78bfa);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.stat .l { font-size: 10px; color: var(--muted); margin-top: 3px; font-weight: 600; letter-spacing: 0.3px; }

/* Профиль */
.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.ph-avatar {
  width: 58px; height: 58px; flex: 0 0 auto; border-radius: 19px;
  display: grid; place-items: center; color: #fff;
  background: var(--grad); box-shadow: var(--glow);
}
.ph-avatar svg { width: 27px; height: 27px; }
.ph-name { font-size: 18px; font-weight: 800; }
.ph-status { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700;
  padding: 5px 10px; border-radius: 999px;
}
.badge.premium {
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.16), rgba(217, 70, 239, 0.16));
  color: var(--gold); border: 1px solid rgba(251, 191, 36, 0.3);
}
.badge.admin {
  background: var(--grad-soft); color: var(--accent-2);
  border: 1px solid rgba(217, 70, 239, 0.35);
}
.badge.free { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

/* Прогресс (серия) */
.streak-track {
  display: flex; align-items: center; gap: 10px;
  margin-top: 12px;
}
.streak-bar {
  flex: 1 1 auto; height: 8px; border-radius: 999px;
  background: var(--surface-2); overflow: hidden;
}
.streak-bar i {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, #fb923c, #d946ef);
  transition: width 0.6s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.streak-next { font-size: 11.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }

.ref-link {
  margin-top: 10px;
  padding: 11px 13px;
  background: rgba(139, 92, 246, 0.08);
  border: 1px dashed rgba(167, 139, 250, 0.35);
  border-radius: 13px;
  font-size: 11.5px;
  color: var(--accent-2);
  word-break: break-all;
  font-family: ui-monospace, monospace;
  line-height: 1.5;
}

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  flex: 0 0 auto;
  padding: 13px 18px; border-radius: 15px; cursor: pointer;
  font-weight: 700; font-size: 14px; font-family: inherit;
  background: var(--grad); border: none; color: #fff;
  box-shadow: var(--glow-sm);
  transition: transform 0.13s, opacity 0.2s;
}
.btn svg { width: 17px; height: 17px; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn.ghost {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); box-shadow: none;
}
.btn.ghost:active { background: var(--surface-3); }
.btn.block { width: 100%; }
.btn.sm { padding: 9px 14px; font-size: 12.5px; border-radius: 12px; }

/* Формы */
.field { display: flex; gap: 8px; }
.field > .btn { flex: 0 0 auto; } /* кнопка рядом с полем — компактная, не на полширины */
.btn-row { display: flex; gap: 8px; }
.btn-row > .btn { flex: 1 1 0; min-width: 0; }
.field input, .input {
  flex: 1 1 auto; min-width: 0;
  padding: 12px 14px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); font-size: 14.5px; outline: none; font-family: inherit;
  transition: border-color 0.2s;
  width: 100%;
}
.field input::placeholder, .input::placeholder { color: var(--muted); }
.field input:focus, .input:focus { border-color: var(--border-strong); }
.select {
  width: 100%; padding: 12px 12px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); font-size: 14px; font-family: inherit; outline: none;
}

/* Сегменты */
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  padding: 9px 13px; border-radius: 11px; font-size: 13px; font-weight: 600;
  font-family: inherit;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.seg button:active { transform: scale(0.96); }
.seg button.active {
  background: var(--grad); border: none; color: #fff;
  box-shadow: var(--glow-sm);
}

/* Настройки: строки */
.set-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.set-row:last-child { border-bottom: none; padding-bottom: 2px; }
.set-ico {
  width: 36px; height: 36px; border-radius: 12px; flex: 0 0 auto;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--primary-2);
}
.set-ico svg { width: 17px; height: 17px; }
.set-main { flex: 1 1 auto; min-width: 0; }
.set-label { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.set-label svg { width: 13px; height: 13px; color: var(--muted); }
.set-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.set-ctrl { flex: 0 0 auto; }

.switch {
  flex: 0 0 auto;
  width: 48px; height: 28px; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--border);
  position: relative; cursor: pointer;
  transition: background 0.25s;
}
.switch::after {
  content: ''; position: absolute; top: 2.5px; left: 3px;
  width: 21px; height: 21px; border-radius: 50%;
  background: #8f84b3;
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.3, 1), background 0.25s;
}
.switch.on { background: var(--grad); border-color: transparent; }
.switch.on::after { transform: translateX(20px); background: #fff; }
.switch.locked { opacity: 0.4; cursor: not-allowed; }

/* Лидерборд */
.podium { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 14px; }
.podium .p-item {
  flex: 1 1 0; min-width: 0;
  border-radius: 16px; padding: 12px 6px 10px;
  text-align: center;
  background: var(--surface-2); border: 1px solid var(--border);
}
.podium .p-item.p1 {
  background: var(--grad-soft); border-color: rgba(251, 191, 36, 0.4);
  padding-top: 16px; padding-bottom: 14px;
}
.p-medal {
  width: 30px; height: 30px; margin: 0 auto 7px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 800; color: var(--bg);
}
.p1 .p-medal { background: linear-gradient(135deg, #fde68a, #f59e0b); box-shadow: 0 4px 14px rgba(245, 158, 11, 0.4); }
.p2 .p-medal { background: linear-gradient(135deg, #e5e7eb, #9ca3af); }
.p3 .p-medal { background: linear-gradient(135deg, #fdba74, #ea580c); }
.p-name {
  font-size: 12px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.p-val { font-size: 10.5px; color: var(--muted); margin-top: 3px; }

.lb-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 4px;
  border-bottom: 1px solid var(--border);
  border-radius: 10px;
}
.lb-row:last-child { border-bottom: none; }
.lb-row.me { background: var(--grad-soft); border: 1px solid var(--border-strong); padding: 11px 10px; }
.lb-rank {
  width: 26px; flex: 0 0 auto; text-align: center;
  font-weight: 800; font-size: 14px; color: var(--muted);
}
.lb-name {
  flex: 1 1 auto; min-width: 0;
  font-weight: 600; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lb-name.me { color: var(--accent-2); }
.lb-val { flex: 0 0 auto; font-size: 12px; color: var(--text-2); text-align: right; }

/* Премиум */
.hero {
  position: relative;
  border-radius: var(--radius);
  padding: 20px 16px;
  margin-bottom: 12px;
  background:
    radial-gradient(120% 140% at 85% 0%, rgba(217, 70, 239, 0.25), transparent 55%),
    radial-gradient(120% 140% at 0% 100%, rgba(139, 92, 246, 0.28), transparent 55%),
    var(--surface);
  border: 1px solid var(--border-strong);
  overflow: hidden;
}
.hero::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255, 255, 255, 0.05) 50%, transparent 70%);
  transform: translateX(-100%);
  animation: sheen 4.5s ease-in-out infinite;
}
@keyframes sheen {
  0%, 55%  { transform: translateX(-100%); }
  85%, 100% { transform: translateX(100%); }
}
.hero .profile-head { margin-bottom: 10px; }

.plan { position: relative; }
.plan.highlight { border-color: rgba(251, 191, 36, 0.35); }
.plan-flag {
  position: absolute; top: -1px; right: 16px;
  padding: 4px 10px; border-radius: 0 0 10px 10px;
  font-size: 10px; font-weight: 800; letter-spacing: 0.6px;
  text-transform: uppercase;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #2a1a03;
}
.plan-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.plan-emoji { font-size: 26px; }
.plan-name { font-weight: 800; font-size: 16px; }
.plan-feat { font-size: 12.5px; color: var(--text-2); margin: 4px 0 12px; }
.plan-feat div { padding: 2.5px 0; display: flex; align-items: center; gap: 8px; }
.plan-feat div svg { width: 13px; height: 13px; color: var(--ok); flex: 0 0 auto; }
.plan-price { display: flex; gap: 7px; flex-wrap: wrap; }
.plan-price button {
  flex: 1 1 30%; min-width: 88px;
  padding: 10px 6px; border-radius: 13px;
  font-size: 12.5px; font-weight: 700; font-family: inherit;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  cursor: pointer; line-height: 1.5;
  transition: background 0.2s, border-color 0.2s, transform 0.12s;
}
.plan-price button small { display: block; font-size: 10.5px; color: var(--muted); font-weight: 600; }
.plan-price button:active { transform: scale(0.96); }
.plan-price button.primary { background: var(--grad); border: none; color: #fff; }
.plan-price button.primary small { color: rgba(255, 255, 255, 0.75); }

/* Админка */
.admin-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.admin-user:last-child { border-bottom: none; }
.au-ava {
  width: 34px; height: 34px; border-radius: 11px; flex: 0 0 auto;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 800; color: #fff;
  background: var(--grad);
}
.au-name { flex: 1 1 55%; min-width: 0; font-size: 13px; font-weight: 600; }
.au-acts { display: flex; gap: 6px; flex-wrap: wrap; }
.au-btn {
  padding: 7px 10px; border-radius: 10px;
  font-size: 11px; font-weight: 700; font-family: inherit;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  cursor: pointer;
  transition: transform 0.12s, background 0.15s;
}
.au-btn:active { transform: scale(0.94); background: var(--surface-3); }
.au-btn.danger { color: var(--danger); }

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px);
  left: 50%; transform: translateX(-50%) translateY(16px);
  background: #1c142f;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 12px 20px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 110;
  box-shadow: var(--shadow);
  max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================================================
   Bottom Sheets (модалки)
   ============================================================ */
.sheet { position: fixed; inset: 0; z-index: 90; display: none; }
.sheet.show { display: block; }
.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(4, 2, 10, 0.65);
  backdrop-filter: blur(4px);
  animation: fade-in 0.25s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-width: var(--app-w); margin: 0 auto;
  background: #140f26;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 26px 26px 0 0;
  padding: 10px 20px calc(env(safe-area-inset-bottom) + 20px);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.6);
  animation: slide-up 0.34s cubic-bezier(0.2, 0.9, 0.3, 1);
  max-height: 86vh;
  overflow-y: auto;
}
@keyframes slide-up {
  from { transform: translateY(60%); opacity: 0.5; }
  to   { transform: translateY(0); opacity: 1; }
}
.sheet-handle {
  width: 38px; height: 4px; border-radius: 999px;
  background: var(--surface-3);
  margin: 4px auto 16px;
}
.sheet-title {
  font-size: 16px; font-weight: 800; text-align: center;
  margin-bottom: 6px;
}
.sheet-sub { text-align: center; margin-bottom: 14px; }
.sheet .btn + .btn { margin-top: 8px; }

.hist-msg { margin-bottom: 10px; }
.hist-who {
  font-size: 10.5px; color: var(--muted); margin-bottom: 4px;
  font-weight: 700; letter-spacing: 0.3px;
}
.hist-text {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 13px; padding: 10px 12px;
  font-size: 13px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}

/* ============================================================
   Гейт (TOS) и системные экраны
   ============================================================ */
.gate {
  position: fixed; inset: 0; z-index: 120;
  background: rgba(5, 3, 12, 0.88);
  backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.gate-card {
  width: 100%; max-width: 400px;
  background: linear-gradient(180deg, #191231, #100b1f);
  border: 1px solid var(--border-strong);
  border-radius: 26px;
  padding: 26px 20px calc(env(safe-area-inset-bottom) + 20px);
  box-shadow: var(--shadow);
}
.gate-logo {
  width: 62px; height: 62px; margin: 0 auto 16px;
  border-radius: 20px;
  display: grid; place-items: center; color: #fff;
  background: var(--grad); box-shadow: var(--glow);
}
.gate-logo svg { width: 30px; height: 30px; }
.gate-card h2 { text-align: center; margin: 0 0 16px; font-size: 19px; }
.tos-body { font-size: 13.5px; color: var(--text-2); line-height: 1.6; max-height: 46vh; overflow-y: auto; }
.tos-body p { margin: 0 0 8px; }
.tos-body ul { margin: 0 0 12px; padding-left: 18px; }
.tos-body li { margin-bottom: 8px; }
.tos-body b { color: var(--text); }
.tos-brand { text-align: center; color: var(--accent-2); font-weight: 700; margin-top: 10px !important; }
.tos-actions { display: flex; gap: 10px; margin-top: 18px; }
.tos-actions .btn { flex: 1; }
