/* ============ MixAutoTrade — glassmorphism UI ============ */
:root {
  --bg0: #070b18;
  --bg1: #0b1226;
  --text: #eaf0ff;
  --muted: #9aa7c7;
  --glass-bg: rgba(255, 255, 255, 0.06);
  --glass-brd: rgba(255, 255, 255, 0.12);
  --glass-hi: rgba(255, 255, 255, 0.18);
  --accent: #5b8cff;
  --accent2: #8a5bff;
  --green: #2fe08a;
  --red: #ff5c72;
  --shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
  --radius: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
body[data-theme="light"] {
  --bg0: #eef2fb;
  --bg1: #dde6fb;
  --text: #10182e;
  --muted: #566188;
  --glass-bg: rgba(255, 255, 255, 0.55);
  --glass-brd: rgba(255, 255, 255, 0.7);
  --glass-hi: rgba(255, 255, 255, 0.9);
  --shadow: 0 8px 30px rgba(40, 60, 120, 0.18);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(140% 120% at 50% 0%, var(--bg1) 0%, var(--bg0) 60%);
  min-height: 100vh;
  overflow-x: hidden;
  padding-bottom: calc(96px + var(--safe-bottom));
}

/* ---- ambient background blobs ---- */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.blob {
  position: absolute; border-radius: 50%; filter: blur(70px); opacity: 0.55;
  animation: float 18s ease-in-out infinite;
}
.b1 { width: 340px; height: 340px; background: #3d63ff; top: -80px; left: -60px; }
.b2 { width: 300px; height: 300px; background: #8a5bff; top: 30%; right: -80px; animation-delay: -6s; }
.b3 { width: 320px; height: 320px; background: #1fb6ff; bottom: -60px; left: 20%; animation-delay: -12s; }
@keyframes float {
  0%,100% { transform: translate(0,0) scale(1); }
  50% { transform: translate(20px,-30px) scale(1.08); }
}

/* ---- glass primitive ---- */
.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-brd);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}
.pad { padding: 16px; }

/* ---- topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  margin: 10px; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-radius: 20px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 14px; font-size: 20px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 6px 18px rgba(91,140,255,0.5);
}
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: 0.2px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.mode-pill {
  border: 1px solid var(--glass-brd); background: var(--glass-hi);
  color: var(--text); font-weight: 700; font-size: 12px;
  padding: 7px 12px; border-radius: 999px; cursor: pointer;
}

/* ---- screens ---- */
main { padding: 6px 12px 0; }
.screen { display: none; animation: fade 0.35s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px);} to {opacity:1; transform:none;} }
.screen-title { font-size: 26px; font-weight: 800; margin: 8px 4px 14px; }

/* ---- search ---- */
.search { padding: 4px 14px; margin-bottom: 12px; border-radius: 16px; }
.search input {
  width: 100%; background: transparent; border: none; outline: none;
  color: var(--text); font-size: 15px; padding: 12px 0;
}
.search input::placeholder { color: var(--muted); }

/* ---- market list ---- */
.list { display: flex; flex-direction: column; gap: 10px; }
.coin {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-radius: 16px; cursor: pointer;
  transition: transform 0.15s ease, background 0.2s;
}
.coin:active { transform: scale(0.98); }
.coin .sym { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 7px; }
.coin .perp { font-size: 9px; font-weight: 800; letter-spacing: 0.5px; color: var(--accent);
  background: rgba(91,140,255,0.14); padding: 2px 5px; border-radius: 5px; }
.market-count { margin: -6px 4px 12px; }
.coin .star { color: var(--muted); font-size: 15px; cursor: pointer; line-height: 1; }
.coin .star.on { color: #ffcf4d; }
.bal-total { font-size: 24px; font-weight: 800; margin-top: 2px; }
.demo-badge { font-size: 10px; font-weight: 800; letter-spacing: 0.5px; color: #ffcf4d;
  background: rgba(255,207,77,0.16); padding: 2px 7px; border-radius: 6px; vertical-align: middle; }

/* ---- trades rows ---- */
.trade.open .t-main { cursor: pointer; flex: 1; }
.trade .t-right { display: flex; align-items: center; gap: 10px; }
.trade .pnl { text-align: right; font-weight: 700; }
.t-close { background: rgba(255,92,114,0.14); color: var(--red);
  border: 1px solid rgba(255,92,114,0.3); border-radius: 10px; padding: 9px 12px;
  font-weight: 700; font-size: 13px; cursor: pointer; white-space: nowrap; }
.t-close:active { transform: scale(0.96); }
.sec-label { font-size: 12px; color: var(--muted); margin: 10px 4px 2px; font-weight: 600; }

/* ---- PnL share card (BingX-style) ---- */
.card-wrap { width: 100%; max-width: 420px; }
.card-wrap .row.gap .btn-ghost, .card-wrap .btn-danger { flex: 1; margin: 0; width: auto; }
.btn-danger { padding: 13px; border: none; border-radius: 14px; cursor: pointer;
  font-weight: 700; font-size: 15px; color: #fff; background: linear-gradient(135deg, #ff5c72, #c23a4d); }
.pcard { position: relative; overflow: hidden; border-radius: 22px; padding: 22px;
  background: radial-gradient(130% 110% at 100% 0%, #12203f, #070b16);
  border: 1px solid var(--glass-brd); box-shadow: var(--shadow); }
.pcard-glow { position: absolute; right: 0; top: 8px; width: 58%; height: 72%; pointer-events: none; }
.pcard-top, .pcard-label, .pcard-pair, .pcard-pct, .pcard-rows, .pcard-foot { position: relative; z-index: 2; }
.pcard-top { display: flex; justify-content: space-between; align-items: center; }
.pcard-brand { font-weight: 800; font-size: 15px; display: flex; align-items: center; gap: 6px; color: #eaf0ff; }
.pcard-brand .logo-sm { color: var(--accent); }
.pcard-mode { font-size: 11px; font-weight: 800; color: #ffcf4d; background: rgba(255,207,77,0.16); padding: 3px 8px; border-radius: 6px; }
.pcard-label { margin-top: 28px; color: #aab3cc; font-size: 15px; font-weight: 600; }
.pcard-pair { margin-top: 10px; font-size: 20px; font-weight: 800; color: #fff; }
.pcard-pair .sep { color: #3a4a6a; margin: 0 4px; }
.pcard-pct { margin-top: 8px; font-size: 46px; font-weight: 900; letter-spacing: -1px; line-height: 1; }
.pcard-rows { margin-top: 20px; display: flex; flex-direction: column; gap: 9px; }
.pcard-rows > div { display: flex; gap: 14px; align-items: baseline; }
.pcard-rows span { color: #8a93ad; font-size: 13px; min-width: 130px; }
.pcard-rows b { color: #fff; font-size: 15px; font-variant-numeric: tabular-nums; }
.pcard-foot { margin-top: 20px; color: #6b7597; font-size: 12px;
  display: flex; justify-content: space-between; align-items: center; }
.pcard-ref b { color: #aab3cc; letter-spacing: 1px; }

/* ---- referrals ---- */
.ref-row { display: flex; justify-content: space-between; align-items: center; margin: 8px 0 4px; }
.ref-code { font-size: 22px; font-weight: 800; letter-spacing: 2px; color: var(--accent); }
.ref-count { font-size: 22px; font-weight: 800; }
.coin .vol { font-size: 12px; color: var(--muted); }
.coin .spark { flex: 1; height: 34px; }
.coin .px { text-align: right; }
.coin .price { font-weight: 700; }
.chg { font-size: 13px; font-weight: 600; }
.chg.up { color: var(--green); }
.chg.down { color: var(--red); }

/* ---- fields / buttons ---- */
.row { display: flex; align-items: center; }
.gap { gap: 10px; }
.field {
  background: var(--glass-hi); border: 1px solid var(--glass-brd);
  color: var(--text); border-radius: 12px; padding: 11px 12px; font-size: 15px; outline: none;
}
.field.wide { width: 100%; }
.tf-group { display: inline-flex; gap: 6px; background: var(--glass-hi); padding: 4px; border-radius: 12px; }
.tf-group button {
  border: none; background: transparent; color: var(--muted);
  padding: 8px 12px; border-radius: 9px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.tf-group button.active {
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2));
}
.btn-primary {
  width: 100%; margin: 14px 0; padding: 15px; border: none; border-radius: 16px;
  color: #fff; font-size: 16px; font-weight: 700; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 10px 26px rgba(91,140,255,0.45);
}
.btn-primary:active { transform: scale(0.99); }
.btn-ghost {
  width: 100%; margin-top: 10px; padding: 13px; border-radius: 14px; cursor: pointer;
  background: var(--glass-hi); border: 1px solid var(--glass-brd); color: var(--text);
  font-weight: 600; font-size: 15px;
}

/* ---- signal card ---- */
.sigcard { margin-top: 14px; overflow: hidden; }
.sigcard .head {
  padding: 16px; display: flex; justify-content: space-between; align-items: center;
}
.sigcard.long .head { background: linear-gradient(135deg, rgba(47,224,138,0.25), transparent); }
.sigcard.short .head { background: linear-gradient(135deg, rgba(255,92,114,0.25), transparent); }
.sigcard .dir { font-size: 20px; font-weight: 800; }
.sigcard.long .dir { color: var(--green); }
.sigcard.short .dir { color: var(--red); }
.sigcard .badge { font-size: 12px; color: var(--muted); }
.levels { padding: 8px 16px 16px; }
.level-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--glass-brd); }
.level-row:last-child { border-bottom: none; }
.level-row .k { color: var(--muted); }
.level-row .v { font-weight: 700; }
.level-row .v.red { color: var(--red); }
.level-row .v.green { color: var(--green); }
.reasons { padding: 0 16px 16px; color: var(--muted); font-size: 13px; line-height: 1.5; }

/* ---- analytics ---- */
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.metric { padding: 14px; border-radius: 16px; }
.metric .label { font-size: 12px; color: var(--muted); }
.metric .value { font-size: 20px; font-weight: 800; margin-top: 4px; }
.tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.tag.up { background: rgba(47,224,138,0.16); color: var(--green); }
.tag.down { background: rgba(255,92,114,0.16); color: var(--red); }
.tag.flat { background: var(--glass-hi); color: var(--muted); }
.verdict { margin-top: 12px; padding: 16px; border-radius: 16px; line-height: 1.5;
  border-left: 3px solid var(--accent); }
.levels-list { margin-top: 12px; }
.levels-list .lv { display: flex; justify-content: space-between; padding: 9px 0;
  border-bottom: 1px solid var(--glass-brd); font-size: 14px; }

/* ---- trades ---- */
.stat-row { display: flex; justify-content: space-between; text-align: center; }
.stat-row .cell .n { font-size: 20px; font-weight: 800; }
.stat-row .cell .l { font-size: 11px; color: var(--muted); }
.trade { padding: 14px 16px; border-radius: 16px; display: flex; justify-content: space-between; align-items: center; }
.trade .s { font-weight: 700; }
.trade .side.long { color: var(--green); }
.trade .side.short { color: var(--red); }
.trade .pnl.up { color: var(--green); }
.trade .pnl.down { color: var(--red); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* ---- profile ---- */
.glass.pad + .glass.pad { margin-top: 12px; }
.profile-head { display: flex; align-items: center; gap: 14px; }
.avatar { width: 48px; height: 48px; border-radius: 16px; display: grid; place-items: center;
  font-size: 22px; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
.setting-title { font-weight: 700; margin-bottom: 10px; }
.switch-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; }
.slider-row { padding: 10px 0; display: flex; flex-direction: column; gap: 8px; }
.slider-row input[type=range] { width: 100%; accent-color: var(--accent); }
.switch { position: relative; width: 46px; height: 27px; display: inline-block; }
.switch input { display: none; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--glass-hi);
  border: 1px solid var(--glass-brd); transition: 0.2s; }
.switch span::before { content: ""; position: absolute; width: 21px; height: 21px; border-radius: 50%;
  background: #fff; top: 2px; left: 2px; transition: 0.2s; box-shadow: 0 2px 6px rgba(0,0,0,0.4); }
.switch input:checked + span { background: linear-gradient(135deg, var(--accent), var(--accent2)); }
.switch input:checked + span::before { transform: translateX(19px); }
.theme-group { display: flex; }
.disclaimer { margin-top: 12px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---- tabbar ---- */
.tabbar {
  position: fixed; left: 10px; right: 10px; bottom: calc(10px + var(--safe-bottom));
  display: flex; justify-content: space-around; padding: 8px 6px; border-radius: 22px; z-index: 30;
}
.tab { border: none; background: transparent; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: 600;
  padding: 6px 8px; border-radius: 14px; flex: 1; }
.tab span { font-size: 18px; }
.tab.active { color: var(--text); }
.tab.active span { color: var(--accent); }

/* ---- modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 50;
  display: none; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(6px);
}
.modal-backdrop.open { display: flex; }
.modal { width: 100%; max-width: 420px; padding: 22px; display: flex; flex-direction: column; gap: 10px; }
.modal h3 { margin: 0; }
#connectMsg.ok { color: var(--green); }
#connectMsg.err { color: var(--red); }

.skeleton { height: 60px; border-radius: 16px; background: var(--glass-bg);
  animation: pulse 1.4s ease-in-out infinite; margin-bottom: 10px; }
@keyframes pulse { 0%,100% { opacity: 0.5;} 50% { opacity: 0.9;} }

/* ================= TradingView chart ================= */
.tv-chart { height: 340px; margin: 12px 0; padding: 6px; overflow: hidden; border-radius: 18px; }
.tv-chart iframe { border-radius: 14px; width: 100% !important; height: 100% !important; }
.tv-chart .empty { padding: 24px; }

/* ================= exchange-style analytics ================= */
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }

/* price hero */
.price-hero { margin-bottom: 12px; }
.ph-top { display: flex; justify-content: space-between; align-items: flex-start; }
.ph-base { font-size: 24px; font-weight: 800; }
.ph-quote { font-size: 14px; color: var(--muted); font-weight: 600; }
.ph-price { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ph-stats { display: flex; justify-content: space-between; margin-top: 14px;
  padding-top: 12px; border-top: 1px solid var(--glass-brd); }
.ph-stats > div { display: flex; flex-direction: column; gap: 3px; }
.ph-stats b { font-variant-numeric: tabular-nums; }

/* liquidation map (leverage → liq price ladder) */
.liq-map { display: flex; flex-direction: column; gap: 6px; }
.liq-row { display: grid; grid-template-columns: 44px 1fr auto auto; align-items: center;
  gap: 10px; padding: 7px 0; }
.liq-lev { font-size: 12px; font-weight: 800; text-align: center; padding: 3px 0;
  border-radius: 7px; }
.liq-lev.short { color: var(--red); background: rgba(255,92,114,0.14); }
.liq-lev.long { color: var(--green); background: rgba(47,224,138,0.14); }
.liq-lev.now { color: var(--text); background: var(--glass-hi); font-size: 11px; }
.liq-track { height: 8px; border-radius: 6px; background: var(--glass-hi); overflow: hidden; }
.liq-bar { height: 100%; border-radius: 6px; }
.liq-bar.short { background: linear-gradient(90deg, transparent, var(--red)); margin-left: auto; }
.liq-bar.long { background: linear-gradient(90deg, var(--green), transparent); }
.liq-price { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; }
.liq-dist { font-size: 12px; font-weight: 700; min-width: 48px; text-align: right; }
.liq-dist.up { color: var(--red); }     /* above price = short liquidation zone */
.liq-dist.down { color: var(--green); }
.liq-row.current { border-top: 1px dashed var(--glass-brd); border-bottom: 1px dashed var(--glass-brd);
  padding: 10px 0; grid-template-columns: 60px 1fr auto; }
.liq-row.current .liq-price { font-size: 17px; font-weight: 800; }
.liq-row.current .liq-dist { color: var(--muted); }

/* sentiment split bar */
.sent-bar { display: flex; height: 30px; border-radius: 10px; overflow: hidden; font-size: 12px;
  font-weight: 800; color: #fff; }
.sent-long { background: linear-gradient(90deg, #1fa86a, var(--green)); display: grid; place-items: center; }
.sent-short { background: linear-gradient(90deg, var(--red), #c23a4d); display: grid; place-items: center; }
