:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --line: #e2e5e9;
  --grid: #f0f2f4;
  --text: #121418;
  --muted: #6b727d;
  --faint: #a1a7b0;
  --accent: #121418;
  --accent-text: #ffffff;
  --up: #14996a;
  --down: #d0444c;
  --warn: #b07418;
  --up-soft: rgba(20, 153, 106, 0.1);
  --down-soft: rgba(208, 68, 76, 0.1);
  --warn-soft: rgba(176, 116, 24, 0.1);
  --shadow: 0 8px 28px rgba(16, 20, 26, 0.1);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0e11; --surface: #13161a; --surface-2: #1a1e23; --line: #22272e; --grid: #191c21;
    --text: #e7e9ec; --muted: #8a919b; --faint: #5a616b; --accent: #e7e9ec; --accent-text: #0c0e11;
    --up: #2bb184; --down: #e0565d; --warn: #d6a144;
    --up-soft: rgba(43, 177, 132, 0.12); --down-soft: rgba(224, 86, 93, 0.12); --warn-soft: rgba(214, 161, 68, 0.12);
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c0e11; --surface: #13161a; --surface-2: #1a1e23; --line: #22272e; --grid: #191c21;
  --text: #e7e9ec; --muted: #8a919b; --faint: #5a616b; --accent: #e7e9ec; --accent-text: #0c0e11;
  --up: #2bb184; --down: #e0565d; --warn: #d6a144;
  --up-soft: rgba(43, 177, 132, 0.12); --down-soft: rgba(224, 86, 93, 0.12); --warn-soft: rgba(214, 161, 68, 0.12);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
input { font: inherit; color: inherit; }
svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.up { color: var(--up); }
.down { color: var(--down); }
.warn { color: var(--warn); }
.top-gap { margin-top: 12px; }
.top-gap-l { margin-top: 18px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

/* ---------- шапка с капиталом */
.account {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: 12px 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.equity { font-size: 22px; font-weight: 600; margin-top: 2px; letter-spacing: -0.01em; }
.account-side { text-align: right; }
.account-side .num { font-size: 14px; font-weight: 600; margin-top: 4px; }

main { padding: 12px 16px 0; }
.view > .section-title:first-child { margin-top: 6px; }

.section-title {
  display: flex; align-items: center; gap: 8px;
  margin: 18px 2px 8px;
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.count { color: var(--faint); }
.tag {
  font-size: 10px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line); color: var(--muted);
}
.footnote { margin: 14px 2px 4px; font-size: 12px; color: var(--faint); line-height: 1.5; }
.footnote a { color: inherit; }
.empty { padding: 22px 14px; text-align: center; color: var(--faint); font-size: 13px; }

.list, .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.list { overflow: hidden; }
.card { padding: 14px; }
.list-head { margin: 14px 2px 8px; }

.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 12px 14px; text-align: left;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
button.row:active { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-end { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; text-align: right; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.coin {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2);
  font-size: 13px; font-weight: 600; color: var(--muted);
}
.pill {
  min-width: 68px; padding: 2px 7px; border-radius: 6px;
  font-size: 12px; text-align: center;
  background: var(--surface-2); color: var(--muted);
}
.pill.up { background: var(--up-soft); color: var(--up); }
.pill.down { background: var(--down-soft); color: var(--down); }
.dot { display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 50%; background: var(--faint); vertical-align: 1px; }
.dot.live { background: var(--up); }

/* ---------- сегменты, поля, чипы */
.seg { display: flex; gap: 3px; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; }
.seg button { flex: 1; padding: 8px 0; border-radius: 7px; color: var(--muted); font-weight: 500; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
.seg-sm button { padding: 5px 0; font-size: 12px; }
.seg-side button.active.long { background: var(--up); color: #fff; box-shadow: none; }
.seg-side button.active.short { background: var(--down); color: #fff; box-shadow: none; }

.field {
  display: flex; align-items: center; gap: 10px;
  height: 46px; margin-top: 10px; padding: 0 12px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
}
.field:focus-within { border-color: var(--muted); }
.field > span:first-child { color: var(--muted); font-size: 13px; white-space: nowrap; }
.field input {
  flex: 1; min-width: 0; text-align: right;
  background: none; border: 0; outline: 0;
  font-size: 16px; font-variant-numeric: tabular-nums;
}
.field input::placeholder { color: var(--faint); }
.suffix { color: var(--muted); font-size: 13px; }

.chips { display: flex; gap: 6px; margin-top: 8px; }
.chips button {
  flex: 1; padding: 6px 0; font-size: 12px;
  border: 1px solid var(--line); border-radius: 8px; color: var(--muted);
}
.chips button.active { color: var(--text); border-color: var(--muted); }

.range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; margin: 16px 0 6px; border-radius: 2px; outline: 0;
  background: linear-gradient(var(--text), var(--text)) 0 / var(--p, 10%) 100% no-repeat, var(--line);
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--text);
}
.range::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--surface); border: 2px solid var(--text); }

.switch-row { display: flex; justify-content: space-between; align-items: center; width: 100%; margin-top: 16px; font-size: 13px; color: var(--muted); }
.switch { position: relative; width: 36px; height: 22px; border-radius: 11px; background: var(--line); transition: background 0.2s; }
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: var(--surface); transition: transform 0.2s;
}
.switch-row[aria-pressed="true"] .switch { background: var(--text); }
.switch-row[aria-pressed="true"] .switch::after { transform: translateX(14px); }

.summary { display: grid; gap: 7px; margin: 16px 0 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.summary div { display: flex; justify-content: space-between; font-size: 13px; }
.summary dt { color: var(--muted); }
.summary dd { font-variant-numeric: tabular-nums; }

.btn { width: 100%; height: 48px; border-radius: 10px; font-size: 15px; font-weight: 600; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-long { background: var(--up); color: #fff; }
.btn-short { background: var(--down); color: #fff; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-ghost { background: var(--surface); border: 1px solid var(--line); }
.btn-ghost.danger { color: var(--down); }
.btn-sm {
  height: 32px; padding: 0 14px; flex: none;
  border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2);
  font-size: 13px; font-weight: 600;
}
.btn-sm.btn-long { border: 0; background: var(--up); color: #fff; }
.btn-sm.btn-short { border: 0; background: var(--down); color: #fff; }
.btn-sm:disabled { opacity: 0.45; }
.btn-sm.soft { border: 0; }
.btn-sm.soft.up { background: var(--up-soft); }
.btn-sm.soft.down { background: var(--down-soft); }

/* ---------- торговля */
.ticker { display: flex; justify-content: space-between; align-items: center; }
.symbol-btn { display: flex; align-items: center; gap: 1px; font-size: 18px; padding: 4px 0; }
.chev { width: 18px; height: 18px; margin-left: 4px; color: var(--muted); }
.ticker-end { text-align: right; }
.ticker-price { font-size: 18px; font-weight: 600; }
.ticker-sub { margin: 0 0 10px; }
.chart {
  height: 280px; margin: 10px 0 12px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}

.pos { margin-bottom: 8px; }
#positions-block { margin-bottom: 18px; }
#positions-block .section-title { margin-top: 4px; }
.pos-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.pos-sym { display: flex; align-items: center; gap: 6px; }
.side-tag { font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 5px; }
.side-tag.long { background: var(--up-soft); color: var(--up); }
.side-tag.short { background: var(--down-soft); color: var(--down); }
.pos-pnl { display: flex; align-items: baseline; gap: 8px; margin: 10px 0 12px; }
.pos-pnl .big { font-size: 20px; font-weight: 600; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 8px; }
.grid3 .num { font-size: 13px; margin-top: 2px; }

/* ---------- P2P */
.balances { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.balances .num { font-size: 16px; margin-top: 2px; }
.banner {
  margin-top: 10px; padding: 10px 12px; border-radius: 10px;
  background: var(--warn-soft); color: var(--warn); font-size: 13px;
}
.deal { margin-top: 8px; padding: 12px 14px; }
.deal-top { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.progress { height: 3px; margin-top: 10px; border-radius: 2px; background: var(--line); overflow: hidden; }
.progress > div { height: 100%; background: var(--text); transition: width 0.5s linear; }
.status { font-size: 12px; font-weight: 600; }
.status.done { color: var(--up); }
.status.scam { color: var(--down); }
.status.frozen { color: var(--warn); }

.offer { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.offer:last-child { border-bottom: 0; }
.offer-top, .offer-bottom { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.offer-bottom { margin-top: 8px; }
.merchant { display: flex; align-items: center; gap: 5px; }
.verified { width: 14px; height: 14px; color: var(--up); stroke-width: 2; }
.offer-rate { font-size: 17px; font-weight: 600; }

/* ---------- рейтинг и профиль */
.rank { width: 28px; flex: none; color: var(--faint); font-weight: 600; font-size: 13px; }
.rank.top { color: var(--text); }
.row.me { background: var(--surface-2); }
.me-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 10px; }
.me-grid .num { font-size: 16px; font-weight: 600; margin-top: 2px; }

.profile-head { display: flex; align-items: center; gap: 12px; margin: 16px 2px 14px; }
.avatar {
  width: 48px; height: 48px; flex: none; overflow: hidden;
  display: grid; place-items: center; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 18px; font-weight: 600; color: var(--muted);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; overflow: hidden; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); }
.stats > div { padding: 12px; background: var(--surface); }
.stats .num { font-size: 15px; font-weight: 600; margin-top: 3px; }

/* ---------- нижнее меню */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar-inner { display: flex; width: 100%; max-width: 560px; }
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 0 9px; color: var(--faint); font-size: 10.5px; font-weight: 500;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--text); }

/* ---------- шторка и уведомления */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, 0.4); opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-width: 560px; max-height: 85vh; margin: 0 auto; overflow: auto;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--surface); border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0;
  transform: translateY(100%); transition: transform 0.25s ease; visibility: hidden;
}
.sheet.open { transform: none; visibility: visible; }
.sheet-grip { width: 36px; height: 4px; margin: 0 auto 14px; border-radius: 2px; background: var(--line); }
.sheet h3 { font-size: 16px; font-weight: 600; }
.sheet .list { margin-top: 12px; }
.sheet .btn { margin-top: 4px; }

.toasts {
  position: fixed; top: calc(8px + env(safe-area-inset-top)); left: 0; right: 0; z-index: 60;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 0 16px; pointer-events: none;
}
.toast {
  width: 100%; max-width: 528px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--muted); border-radius: 10px;
  box-shadow: var(--shadow); opacity: 0; transform: translateY(-8px); transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.success { border-left-color: var(--up); }
.toast.error { border-left-color: var(--down); }
.toast.warn { border-left-color: var(--warn); }
.toast.has-action { display: flex; align-items: center; gap: 12px; pointer-events: auto; }
.toast-body { flex: 1; min-width: 0; }
.toast-action {
  flex: none; height: 32px; padding: 0 12px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; font-weight: 600;
}
.toast-title { font-size: 13px; font-weight: 600; }
.toast-text { font-size: 13px; color: var(--muted); margin-top: 1px; }

.blocker {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 32px; text-align: center;
  background: var(--bg); color: var(--muted);
}

/* ---------- шеринг и приглашения */
.card-preview {
  aspect-ratio: 1200 / 675; overflow: hidden; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
}
.card-preview img { display: block; width: 100%; height: 100%; object-fit: cover; }
.icon-btn {
  width: 34px; height: 34px; flex: none; display: grid; place-items: center;
  border-radius: 8px; color: var(--muted);
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:active { background: var(--surface-2); }
.invite-text { margin-top: 6px; line-height: 1.5; }
.invite-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.invite-stats .num { font-size: 16px; margin-top: 2px; }
.link-box {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 44px; margin-bottom: 10px; padding: 0 12px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  color: var(--muted); font-size: 13px; text-align: left;
}
.link-box span { flex: 1; min-width: 0; }
.link-box svg { width: 18px; height: 18px; flex: none; }

/* ---------- канал автора */
.promo {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.promo:active { background: var(--surface-2); }
.promo-icon, .channel-icon {
  flex: none; display: grid; place-items: center; border-radius: 50%;
  background: var(--up-soft); color: var(--up);
}
.promo-icon { width: 36px; height: 36px; }
.promo-icon svg { width: 20px; height: 20px; }
.chev-r { width: 18px; height: 18px; flex: none; color: var(--faint); }
.channel-body { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; }
.channel-body p { line-height: 1.5; margin-bottom: 6px; }
.channel-icon { width: 56px; height: 56px; margin-bottom: 2px; }
.channel-icon svg { width: 28px; height: 28px; }
.link-btn { padding: 8px 16px; color: var(--muted); font-size: 14px; }
.gate {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  padding: 24px max(16px, env(safe-area-inset-left)); background: var(--bg);
}
.gate .channel-body { width: 100%; max-width: 420px; }
